Create an alert page in view/admin/users/ with the name alert.blade.php
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
Include file file in the login page
Edit function store in the controller to validate the form
public function store(Request $request)
{
//
//dd($request->input());
$validated = $request->validate([
'email' => 'required',
'password' => 'required',
]);
}
The result of validation
Authentication
After validation, we do the authentication
public function store(Request $request)
{
//
//dd($request->input());
//$remmeber = isset($request->input('rememeber'))? true: false;
$this->validate($request,[
'email'=>'required|email|email:filter',
'password'=>'required'
]);
if (Auth::attempt(
['email'=>$request->input('email'),
'password'=>$request->input('password')]
,$request->input('remember')))
{
return redirect()->route('admin');
}
return redirect()->back();
}
In the authentication, we verify the email, password by using the information saved in the DB. The remember field is taken into account.
If it is correct, we redirect to route admin/main.
Add the route in the web.php file
Route::get('/admin/main',[MainController::class, 'main'])->name('admin');
This route point to the main class in the MainController class. So we create a class MainController in Admin by
php artisan make:controller Admin\MainControlle
Create a main function
class MainController extends Controller
{
//
public function main(){
echo "Welcome Admin";
}
}
So we have the result