Table of Contents
We know that in lots of dynamic applications login , register, forgot password is must. Laravel has inbuilt these features . So, we have very easy steps to achieve this in our application.
Below I have described steps to setup Login, Registration and password reset (authentication system) in our Laravel project.
Laravel UI is a new package since Laravel 6 that extracts the UI portion of a Laravel project into a separate laravel/ui package /home' .
But we need to redirect to our index page i.e 'https://localhost//'
To do so, open app/Http/Controllers/Auth/RegisterController.php
and app/Http/Controllers/Auth/LoginController.php
and change
Install laravel/ui Package
execute below command
Once you've installed laravel/ui you have a couple of commands available to generate UI code, including authorisation.
If you intend to use Vue, React, or Bootstrap, the UI package provides the following command:
Generate the auth scaffolding
to generate the auth scaffolding at the same time:
Note:
If showing error like .. bootstrap-stubs/bootstrap.js no such file or directory then copy the bootstrap.js file ( find in this tutorial) and
put inside inside vendor/laravel/ui/src/Presets/bootstrap-stubs/
then re-run above command i.e php artisan ui bootstrap --auth
it will generate the auth routes, a HomeController, auth views, and a app.blade.php layout file.
Note: this command create lots of views inside resources/views
So, if yo have a view name home.blade.php ,do backup/rename it .
After executing this command ,you can restore it resources/views/auth/login.blade.php resources/views/auth/register.blade.php resources/views/auth/passwords/email.blade.php resources/views/auth/passwords/reset.blade.php resources/views/auth/emails/password.blade.php resources/views/layouts/app.blade.php resources/views/home.blade.php resources/views/welcome.blade.php
controller 'HomeController'
It will create controller 'HomeController' It will also append below lines in your route file routes/web.php
Login,register in menu
open https://localhost/laravel/login Put login,register in menu - Put below inside our master layout file of resources/view/layout/master.blade.php (note: put inside ul tag ..) It is also mentioned in resources/view/layouts/app.blade.php (line no. 44 to 68)
Testing
Now to test these pages open login page in your browser ex:
Fix css loading issue
By default css loading issue. To fix open , Open login.blade.php, register.blade.php (found under resources/view/auth) and replace above 2 line with below
By default after registration or login, it redirect to 'https://localhost/
to
Now It will show login and register link on your main menu .
We also have drop down menu for logged in user. In next tutorial i will describe on how to add custom field on registration page . We have a advance level of Laravel course that cover an ecommerce project from scratch. If you interested joining, contact us. Contact us If you looking to hire experienced PHP Laravel Developer .