我無法在Laravel中進行用戶登錄。我正在使用username
而不是email
。無法在laravel中實現身份驗證方法
下面是我的路線
use App\Message;
Route::get('/', function() {
return view('welcome');
});
//
Route::post('/contact','[email protected]');
Route::get('/admin9419/dashboard','[email protected]')->name('dash');
Route::get('/admin9419/login','[email protected]')->name('home');
Route::post('/admin9419/login','[email protected]');
Route::post('/admin9419/logout','[email protected]');
這是我SessionController文件
<?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');
}
}
錯誤:
Type error: Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable
用戶等級:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
//
}
任何人都可以幫助我錯過了什麼?
仍然有相同的錯誤。 – Abhishek
我已編輯我的帖子,我試過你的代碼,它的工作,你可以發佈我一個類的用戶? 是否用戶類擴展Authenticatable? – LorenzoBerti
添加用戶類文件 – Abhishek