当用户从登录返回主页时出现此错误我不明白我在 Laravel 5 中执行 MultiAuth 是什么,如果我可以使用登录功能和其他已可用于用户表的注册功能,我也会帮助我不知道如何使用已经编写的函数来做到这一点

这是我的登录功能

public function login()
    {
        $data = Input::all();

        // Applying validation rules.
        $rules = array(
            'email' => 'required|email',
            'password' => 'required|min:6',
        );

        $validator = Validator::make($data, $rules);

        if ($validator->fails()){
            // If validation falis redirect back to login.
            return Redirect::to('admin/login')->withInput(Input::except('password'))->withErrors($validator);
        }
        else {
            $userdata = array(
                'email' => Input::get('email'),
                'password' => Input::get('password')
            );
        }

        // doing login.
        if (Auth::validate($userdata)) {
            if (Auth::attempt($userdata)) {
                return Redirect::intended('admin');
            }
        }
        else {
            // if any error send back with message.
            Session::flash('error', 'Something went wrong');
            return Redirect::to('admin/login');
        }
    }

这是我的 AdminController
<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class AdminController extends Controller
{
//    public function __construct(){
//
//        $this->middleware('admins');
//    }
    public function index(){
//        $user = Auth::user();
//        dd($user);
        return view('admin.home');
    }
}

最佳答案

添加到您的 Controller :

protected $guard = 'admin';

public function login()
{
    $data = Input::only(['email', 'password']);

    // Applying validation rules.
    $rules = array(
        'email' => 'required|email',
        'password' => 'required|min:6',
    );

    $validator = Validator::make($data, $rules);

    if ($validator->fails()){
        // If validation falis redirect back to login.
        return Redirect::to('admin/login')
            ->withInput(Input::except('password'))
            ->withErrors($validator);
    }

    if (Auth::->attempt($userdata)) {
        return Redirect::intended('admin');
    }
    return Redirect::to('admin/login')
        ->with('error', 'Something went wrong');
}

关于php - 类 App\Http\Controllers\AdminController 不存在,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37409825/

10-12 12:22