Welcome to the Laravel API repository! This project showcases a robust implementation of a RESTful API using Laravel, adhering to best practices. It features secure authentication with Laravel Sanctum, comprehensive API documentation with OpenAPI/Swagger, and polymorphic relationships for flexible data modeling.
Laravel Sanctum Authentication:
Secure authentication for your API using Laravel Sanctum, ensuring safe access to protected routes.
OpenAPI/Swagger Integration:
Detailed API documentation powered by OpenAPI/Swagger, providing a clear and interactive interface for developers.
Polymorphic Relationships:
Flexible data modeling with Laravel's polymorphic relationships, allowing Category to belong to both Post and Product models.
Best Practices:
Follows Laravel's best practices, including: Clean and organized code structure. Exception handling and transaction management. Use of repositories and service classes for better code separation. Comprehensive API responses.
Clone the repository:
git clone https://github.com/shahzadthathal/laravel-api
cd laravel-api
composer install
cp .env.example .env
php artisan key:generate
Configure your database settings in the .env file.
Also update L5_SWAGGER_CONST_HOST
variable for swagger url if needed.
php artisan migrate --seed
php artisan serve
Access the interactive API documentation at /api/swagger
http://127.0.0.1:8000/api/swagger
Register a user: /api/register
Login a user: /api/login
Protected Routes:
Accessible only with a valid Sanctum token.
Examples: /api/categories (store, update, delete)
Public Routes:
Accessible without authentication.
Examples: /api/categories (index, show)
cd laravel-api
php artisan l5-swagger:generat
Contributions are welcome! Please open an issue or submit a pull request for any improvements, bug fixes, or new features.
This project is licensed under the MIT License. See the LICENSE file for details.