Laravel Default Authentication Setup
In this article, We will discuss Laravel Default Authentication Setup. Laravel is a great PHP framework and currently, it’s the most starred PHP project on GitHub. Today, I will show you how easy it to add authentication to it without writing more logic.
Laravel makes authentication more simple. You need to configure it. I’m assuming, you are familiar with the setup of Laravel. If not then please check our Laravel Setup guide.
Next, Open your terminal and execute the given artisan command.
php artisan make:auth
Please note that run this command only on a fresh copy of Laravel project.
After executing the command. Some of the files known as Authentication scaffolding generated into our application, routes have also been updated.
Route::auth() is a method that cleanly contains all the login and register routes.
Now, You can get all the views related to the authentication located under
resources/views/auth directory. All these views use the Bootstrap CSS and you can customize as per your requirement.
Now, time to check our application.
Laravel provides wonderful feature *migration*. It’s like version controlling for database and allowing us to easily manage the database schema. In Laravel, all the migration files placed in the *database/migrations* directory. Each migration file name contains the timestamps which allow Laravel to manage the order of the migrations.
The user migration files come with the Laravel by default. Check the database/migrations folder and confirm you have at least two files named ***_create_users_table.php and ***_create_password_reset_table.php. Here’s *** represents the timestamp.
Now, time to execute these migrations using given a command.
php artisan migrate
Ensure the database name and user credentials are set in your .env file.
Middlewares provide a wonderful mechanism for filtering HTTP requests. Laravel includes auth middleware that verifies the user of our application is authenticated. If the user is not authenticated, the middleware will redirect to the login screen. If a user is authenticated, the middleware allowed to proceed with the request. You can get the auth middleware at
app/Http/Middleware directory. We will discuss Middleware in another post. Let’s focus currently on Authentication.
Everything is ready now, you can start from registration. Feel free to comments for any query.
If you like our content, please consider buying us a coffee.
Thank you for your support!
Buy Me a Coffee