auth.php在将模型从用户更改为admin时出现问题

时间:2014-12-08 08:55:52

标签: authentication laravel

请猜我要问auth.php只接受用户界面类。 bcos我有一个管理员表,我没有用户表,这是我的代码。

控制器

<?php
/**
 *Manages the login from the front page to the questionnaire page.
 *
 * @author Udeme <udeme@gmail.com> (Lead Developer/Partner)
 * @copyright Meliorem Media Sollutions 2015
 * --------------------------------------------------------
 * 
 */

class AdministratorController extends Controller {

    public function login(){

        $adminName = Input::get('name');
        $adminPass = Input::get('pass');

        if (Auth::attempt(array('name' => $adminName, 'password' => $adminPass)))
        {
            $adminTable = Admin::where('name', '=', $adminName)->first();
            $adminEmail = $adminTable->email;
            $adminEmail = Session::put('adminEmail',$adminEmail);

            return Redirect::intended('question1'); 
        }else{
            return Redirect::to('/')-> with('message', 'Your username/password combination was incorrect... Are you sure you are the admin?');
        }


    }

}

AUTH.PHP app / config / auth.php

<?php

return array(

/*
|--------------------------------------------------------------------------
| Default Authentication Driver
|--------------------------------------------------------------------------
|
| This option controls the authentication driver that will be utilized.
| This driver manages the retrieval and authentication of the users
| attempting to get access to protected areas of your application.
|
| Supported: "database", "eloquent"
|
*/

'driver' => 'eloquent',

/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/

'model' => 'Admin',

/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/

'table' => 'admins',

这是错误

Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Auth\UserInterface, instance of Admin given, called in /var/www/html/mquestions/vendor/laravel/framework/src/Illuminate/Auth/Guard.php on line 371 and defined.

那是什么原因? 隐私

1 个答案:

答案 0 :(得分:0)

您需要在Admin类中实现接口Illuminate\Auth\UserInterface的方法。