Laravel 5.2错误App \ User无法使用Illuminate \ Foundation \ Auth \ User - 它不是特征

时间:2016-05-15 09:05:43

标签: php laravel authentication laravel-5.2

我对laravel 5.2很新。现在我正在尝试创建自定义登录。我创建了登录html。在提交时,该函数显示错误

  

App \ User无法使用Illuminate \ Foundation \ Auth \ User - 它不是特质

我无法找到错误。代码在

之下

routes.php文件

Route::post('/', 'Admin\LoginController@postLogin');

LoginController.php

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;

use Auth;
use Request;


class LoginController extends Controller {

public function index() {
    return view('admin.login');
}

public function register() {
    return view('admin.register');
}

public function postLogin() {
    $email = Request::input('email');
    $password = Request::input('password');

    if (Auth::attempt(['email' => $email, 'password' => $password])) {
        //echo "success";
        return redirect('admin/dashboard');
    } else {
        return redirect('/');
    }
}

}

user.php的

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

use Authenticatable,
    CanResetPassword;

protected $table = 'users';
protected $fillable = ['name', 'email', 'password'];
protected $hidden = ['keyword', 'remember_token'];

}

Auth.php

<?php

return [



'defaults' => [
    'guard' => 'web',
    'passwords' => 'users',
],

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],
    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],
],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],
    'users' => [
        'driver' => 'eloquent',
        'model' => 'App\User',
        'table' => 'users',
        'password' => [
            'email' => 'emails.password',
            'expire' => 60,
        ],
    ],
],

'passwords' => [
    'users' => [
        'provider' => 'users',
        'email' => 'auth.emails.password',
        'table' => 'password_resets',
        'expire' => 60,
    ],
],
];

我正在关注here

中的教程

请帮帮我。我在最近几个小时被困在这里

1 个答案:

答案 0 :(得分:12)

您应该使用此命名空间:

use Illuminate\Auth\Authenticatable;

这是你应该使用的特质。现在,您正在尝试使用类作为特征:

use Illuminate\Foundation\Auth\User as Authenticatable;

class User {

    use Authenticatable ...