My Route is this
I tried using Guard method authentication and could not resolve it please help!! what could be the reason for these errors? If there is no specified content then please let me know.
Route::group(['middleware' => 'auth:admin',function(){
Route::get('/dashboard', [AdminController::class, 'dashboard']);
}]);
here is the link where you can see through image My error image
My AdminController if needed
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator;
use App\Models\admin;
use Session;
use Auth;
class AdminController extends Controller
{
public function index(){
return view('admin.login');
}
public function makeLogin(Request $request){
$validator = Validator::make($request->all(), [
'username' => 'required',
'password' => 'required'
]);
if($validator -> fails()){
return back()
-> withErrors($validator)
-> withInput();
}
$data = array(
'username' => $request->username,
'password' => $request->password,
);
if(Auth::guard('admin')->attempt($data)){
return redirect('dashboard');
}else{
return back()->withErrors(['message' => 'invalid email or password']);
}
}
public function dashboard(){
return view('admin.dashboard');
}
}
CodePudding user response:
You should set only middleware in array.
Route::group(['middleware' => 'auth:admin'],function(){
Route::get('/dashboard', [AdminController::class, 'dashboard']);
});
CodePudding user response:
You just forgot and add the callback function inside the array
it should be the second parameter like this
Route::group(['middleware' => 'auth:admin'],function(){
Route::get('/dashboard', [AdminController::class, 'dashboard']);
});
you could also write it like this
Route::middleware(['middleware' => 'auth:admin'])->group(function() {
Route::get('/dashboard', [AdminController::class, 'dashboard']);
});