ref: https://www.positronx.io/laravel-custom-authentication-login-and-registration-tutorial/
Laravel 9 Custom Auth Login and Registration Tutorial
Laravel custom login and registration tutorial; In this tutorial, we will explain how to create custom authentication login and registration in the Laravel application.
Laravel is a top-notch PHP framework that is a boon for web developers, and it offers numerous packages and plugins to build any type of functionality.
When we talk about the authentication feature, you can install and use the Laravel JetStream package.
Having said that, we are going to share with you the traditional method through which you can create custom authentication in laravel.
This quick guide, bit by bit, describes the simple method to build custom login, registration and dashboard pages or templates.
Laravel 9 Custom Auth Login and Registration Example
- Step 1: Create Laravel App
- Step 2: Connect to Database
- Step 3: Set Up Auth Controller
- Step 4: Create Auth Routes
- Step 5: Create Auth Blade View Files
- Step 6: Run Laravel Development Server
Create Laravel App
We assume you have already configured Composer on your system, run the following command to install the new laravel app. However, you can skip this step if the app is already installed.
Next, head over to app folder:
Connect to Database
Now, you have to add database name, username, and password into the .env configuration file to connect the laravel app to the database:
If you are using MAMP local server in macOs; make sure to append UNIX_SOCKET and DB_SOCKET below database credentials in .env file.
The laravel app comes with a default User model and migration file, and we only have to run the following command to create the new table inside the database. So, get to the terminal and execute the following command to run the migration.
Set Up Auth Controller
Next, type the suggested command on the command prompt and execute the command to generate a new controller file by the name of CustomAuthController.
Thereafter, open app\Http\Controllers\CustomAuthController.php file and carefully place the following code within the file.
Create Auth Routes
This step explains how to create routes with POST and GET methods for handling custom authentication in laravel application. Consequently, open and add the recommended code in the routes/web.php file:
Create Auth Blade View Files
You need to create auth folder in resources/views/ folder and likewise create a new login.blade.php file within, there after place the following code in resources/views/auth/login.blade.php file:
You have to move to resources/views/auth folder, similarly create a new registration.blade.php file within, after that update the suggested code in the resources/views/auth/registration.blade.php file:
Head over to resources/views/ folder, then create the new dashboard.blade.php file, then add the given below code in the resources/views/dashboard.blade.php file:
Run Laravel Development Server
Finally, we need to run the laravel development server, which will help us start the app on the browser. Ensure that you execute the given below command through the command prompt.
Add the following url on the browser’s address bar and test the app recklessly.
Conclusion
Laravel custom authentication tutorial is over.
This quick guide helped us ascertain how to smoothly and effortlessly create a user login and user registration in the laravel app without using any third-party or external plugin or package.
View File Code :
https://drive.google.com/file/d/1aZ4hN7y7lfGuIlfXf4S2zjKGAck9P5dx/view?usp=share_link