I am using Laravel latest version 9 When writing the code I know now I am not an expert.
I encountered this error even though I applied everything correctly from the video clip.
Any help :)
my error : https://flareapp.io/share/q5YMDKj5#F48 .
my code admin.php:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class Admin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
if(!Auth::guard('admin')->check()){
return redirect('/admin/login');
}
return $next($request);
}
}
my code adminController.php:
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Middleware\Authenticate;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class AdminController extends Controller
{
public function dashboard(){
return view('admin.dashboard');
}
public function login(Request $request){
if ($request->isMethod('post')) {
$data = $request->all();
// echo "<pre>"; print_r($data); die;
if (Auth::guard('admin')->attempt(['email'=>$data['email'],'password'=>$data['password'],'status'=>1])) {
return redirect('admin/dashboard');
}else{
return redirect()->back()->with('error_message','Invalid Email or Password');
}
}
return view('admin.login');
}
}
CodePudding user response:
Please Where's Your Admin Model