douzhaiya3968 2017-10-04 14:35
浏览 251
已采纳

无法在laravel中实现authenticate方法

I am not able to make a user login in Laravel. I am using username instead of email.

Below is my Routes

use App\Message;

Route::get('/', function () {
    return view('welcome');
});
//


Route::post('/contact','MessageController@store');

Route::get('/admin9419/dashboard','AdminDashboardController@index')->name('dash');
Route::get('/admin9419/login','SessionsController@create')->name('home');
Route::post('/admin9419/login','SessionsController@store');
Route::post('/admin9419/logout','SessionsController@destroy');

This is my SessionController File

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class SessionsController extends Controller
{



    public function __construct()
    {

        $this->middleware('guest');

    }


    public function create(){


        return view('sessions.create');


    }


    public function destroy(){

        auth()->logout();

        return redirect()->home();

    }

    public function store(){



       if(!auth()->attempt(['username'=>request('username'),'password'=>request('password')])){

           return back();

       }

       return redirect('/admin9419/dashboard');


    }

}

Error:

Type error: Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable

User class:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    //
}

Can anyone help what i missed?

  • 写回答

3条回答 默认 最新

  • dqitk20644 2017-10-04 15:00
    关注

    The code seems correct.

    See the Class User that it should be something like:

     use App\Notifications\MailResetPasswordToken;
    use Illuminate\Notifications\Notifiable;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    
    class User extends Authenticatable
    {
        use Notifiable;
        ....
    }
    

    So can you paste the User class?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里