Users management with Laravel


  • Create the tree structure of your client application indicating all the cleint pages (html) and their potential link.


Part 1 – block the uri

Delievrable : otelo/mission4/…

  • create a view indicating that the user needs to sign in

<div class="jumbotron">
    <h2 class="my-5 text-center"> authentification nécessaire </h2>


  • in web.php, add middleware (‘auth’) on the route of creation of a booking
Route::get('/newReservation',[ReservationController::class, 'create'] ->middleware('auth');
Route::get('/failure',function () {
    return view('failure');
  • in middleware/Authenticate.php, modify the function
if (! $request->expectsJson()) {
            return route('failure');
  • test the route, it is secured, sign in will be needed.


It is also possible to secure all the routes of a controller by adding, in it :

public function __construct(){

The middleware condition (‘auth’) in the route becomes useless.


Part 2 – authentication system

Deliverable : otelo/mission4/…

  • Generate the authentication skeleton
composer require laravel/ui
php artisan ui vue --auth
php artisan ui react --auth
php artisan migrate
  • Test the registration of a user with the uri register


  • Create the /auth/compte.blade.php view and the account uri

    <div class="section">
        <h1 class="title is-1">Mon compte</h1>

        <p>Vous êtes bien connecté.</p>

        <a href="/deconnexion" class="button">Déconnexion</a>
  • Create the uri disconnection
Route::get('/deconnexion',function () {
    return redirect('/');
  • Add the logout button to the uri /
  • Redirect the user to the root of the site by modifying the Login controller
//protected $redirectTo = RouteServiceProvider::HOME;
protected $redirectTo = '/';




  • Test if the user is logged in