Skip to content

A professional API showcasing Laravel best practices for crud, authentication, validation, and clean architecture.

Notifications You must be signed in to change notification settings

fathallah7/laravel-best-practices-api

Repository files navigation

Laravel Logo

Laravel API - Best Practices Project

A professional API showcasing Laravel best practices for crud, authentication, validation, testing, and clean architecture.

📖 Features || Best Practices Implemented

  • ✅ RESTful API with versioning (v1)
  • ✅ JWT Authentication (Laravel Sanctum)
  • ✅ Policies (Authorization logic)
  • ✅ Repository Pattern
  • ✅ Service Layer
  • ✅ Form Request Validation
  • ✅ API Resources
  • ✅ Comprehensive error handling
  • ✅ Pagination & Filtering
  • ✅ Soft Deletes
  • ✅ Feature & Unit Tests
  • ✅ API Documentation

🏗️ Project Structure

app/
├── Http/
│   ├── Controllers/
│   │   └── Api/
│   │       └── V1/
│   │           ├── AuthController.php
│   │           └── TaskController.php
│   ├── Requests/
│   │   ├── StoreTaskRequest.php
│   │   └── UpdateTaskRequest.php
│   ├── Resources/
│   │   ├── TaskResource.php
│   │   └── TaskCollection.php
├── Models/
│   ├── User.php
│   └── Task.php
├── Services/
│   └── TaskService.php
├── Repositories/
│   ├── Contracts/
│   │   └── TaskRepositoryInterface.php
│   └── Eloquent/
│       └── TaskRepository.php
├── Policies/
│   └── TaskPolicy.php
├── Exceptions/
│   └── ApiHandler.php
└── Traits/
    └── ApiResponse.php

database/
├── migrations/
│   ├── 2025_12_01_082837_create_tasks_table.php
├── factories/
│   └── TaskFactory.php
└── seeders/
    ├── DatabaseSeeder.php
    └── TaskSeeder.php

tests/
├── Feature
│   └── TaskTest.php
└── Unit/
    └── TaskServiceTest.php

📋 Requirements

  • PHP 8.2+
  • Composer
  • MySQL 8.0+

🛠️ Installation

1. Clone & Install Dependencies

git clone https://github.com/fathallah7/laravel-best-practices-api.git
cd laravel-best-practices-api
composer install

2. Environment Setup

cp .env.example .env
php artisan key:generate

Configure your .env:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel-best-practices-api
DB_USERNAME=root
DB_PASSWORD=

3. Database Setup

php artisan migrate --seed

4. Run Server

php artisan serve

API will be available at: http://localhost:8000/api/v1

🤝 Contributing

This project is educational. Feel free to fork and learn!

📝 License

MIT License


⭐ If this helps you learn Laravel best practices, give it a star!

About

A professional API showcasing Laravel best practices for crud, authentication, validation, and clean architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages