This is a simple authentication project built with Laravel 11. It includes user registration, login, and logout functionality. The project demonstrates how to build a basic authentication system using Laravel's built-in authentication capabilities.
- User registration
- User login/logout
- Form validation with Bootstrap styling
- Alert messages for success and error handling
- Protected dashboard accessible only after login
Before running this project, make sure you have the following installed on your system:
- PHP 8.1 or higher
- Composer
- MySQL or any database supported by Laravel
- Node.js and npm (for Laravel Mix and frontend build tools)
- Laravel 11
git clone https://github.com/your-username/laravel-auth-project.git
cd laravel-auth-project
Install the required PHP dependencies using Composer:
composer install
Install the required frontend dependencies (if applicable):
npm install
Copy the .env.example
file to .env
:
cp .env.example .env
Update the following lines in your .env
file to match your database configuration:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_auth
DB_USERNAME=your_db_username
DB_PASSWORD=your_db_password
Laravel requires an application key for encryption purposes. Generate the key using the following Artisan command:
php artisan key:generate
Create a new MySQL database named laravel_auth
(or update the database name in the .env
file as necessary):
CREATE DATABASE laravel_auth;
Run the database migrations to set up the necessary tables:
php artisan migrate
Start the local development server using the Artisan CLI:
php artisan serve
You can now access the application at http://127.0.0.1:8000
.
If you modify any frontend assets (e.g., CSS or JavaScript), you can compile them using Laravel Mix:
npm run dev
To compile for production:
npm run prod
- Register a new user: Visit
/register
and create a new account. - Login: Use the credentials from registration to log in via
/login
. - Dashboard: Once logged in, you will be redirected to the dashboard. This page is protected and only accessible to authenticated users.
- Logout: Click the logout button in the dashboard to log out of your account.
- Routes: Defined in
routes/web.php
. - Views: Located in
resources/views
for templates like login, register, and dashboard. - Controllers: Auth-related logic is handled in
app/Http/Controllers/AuthController.php
. - Middleware: Route protection is managed via the
auth
middleware inapp/Http/Middleware
.
- If you encounter any issues with the environment variables, make sure your
.env
file is correctly configured. - Ensure that you have the proper database credentials in the
.env
file and that your MySQL server is running.
This project is open-source and available under the MIT license.