Step 1: Install Laravel UI
Run the following commands in your terminal to install Laravel UI, which will help you create the basic scaffolding for authentication:
Step 2: Install Laravel Project
Install a new Laravel project by running the following command:
Step 3: Setup Database Credentials
Create a new database custom_auth
in your MySQL. Then, open your .env
file and add the following database credentials:
Run the migration command to generate tables in the database:
Step 4: Add Custom CSS (Optional)
Create a custom CSS file at public/assets/css/style.css
for styling your login and registration pages. Here's a basic example of the CSS:
Step 5: Create Routes for Registration and Login
In the routes/web.php
, create routes for registration and login:
Step 6: Create RegisterController
Generate the RegisterController
to handle the registration process:
Then, add the following code to RegisterController.php
:
Step 7: Create LoginController
Generate the LoginController
to handle the login process:
Then, add the following code to LoginController.php
:
Step 8: Create Views for Registration and Login
Create the login and registration views in the resources/views/auth/
directory.
Register View (register.blade.php
):
Login View (login.blade.php
):
Step 9: Create HomeController
Generate a HomeController
to show the home page after a successful login:
Add the following code to HomeController.php
:
Step 10: Create Home Page View
Create a home.blade.php
file to display after successful login:
Step 11: Add Auth Middleware
To restrict access to the home page only for authenticated users, use the auth
middleware in your routes:
Step 12: Final Steps
-
Run
php artisan serve
to start your Laravel server. -
You can access the registration and login pages by navigating to
http://127.0.0.1:8000/register
andhttp://127.0.0.1:8000/login
.