![]() |
![]() |
![]() |
This project is an extended version of the Laravel 10 source code designed to provide a template for JWT authentication-based REST API server applications with a full user authentication cycle.
This is a starter template for developing REST API applications using Laravel 10 and JWT-auth.
It includes:
- A clean REST API implementation.
- Client JWT authentication with all necessary options: authentication with getting bearer token, token refreshing, etc.
- User authentication, including: registration (with email verification), authentication (login and logout), password changing, and so on.
These instructions will help you clone and run the project on your local machine for development and testing purposes.
Necessary:
Optional:
If not using Laravel Sail:
- MySQL or another supported database.
Run this shell script in the root of the project:
./setup.sh
-
Clone the repository:
git clone https://github.com/kublahanov/laravel-10-template.git cd laravel-10-template
-
Install dependencies via Composer:
composer install
-
Copy the
.env.example
file to.env
(if it not completed automatically in step 2):cp .env.example .env
-
Generate the application key (if it not completed automatically in step 2):
php artisan key:generate
-
Configure your database settings in the
.env
file. -
Run the database migrations:
php artisan migrate
-
Start the local development server (or use Laravel Sail):
php artisan serve
Your application should now be accessible at http://localhost:8000
.
- JWT Authentication: Implemented using the
tymon/jwt-auth
package. - REST API: All routes and controllers for auth-based API.
POST /api/auth/register
{
"name": "John Doe",
"email": "john.doe@example.com",
"password": "password",
"password_confirmation": "password"
}
Response:
{
"message": "User registered successfully, please check your email for verification link",
"user": {
"name": "John Doe",
"email": "john.doe@example.com",
"updated_at": "2024-06-26T18:03:49.000000Z",
"created_at": "2024-06-26T18:03:49.000000Z",
"id": 1
}
}
POST /api/auth/login
{
"email": "john.doe@example.com",
"password": "password"
}
Response:
{
"access_token": "your-jwt-token",
"token_type": "bearer",
"expires_in": 3600
}
For deploying on a production server, it is recommended to follow these steps:
- Install all dependencies and run the migrations.
- Configure your web server (e.g., Nginx or Apache) to work with Laravel.
- Ensure you have the appropriate caching and session levels set up.
If you have suggestions for improving this project or want to report a bug, please open an issue or create a pull request.
This project is licensed under the MIT license.