Features:
- Automated file generation: When you run the
php artisan make:repository
command, the following files will be automatically generated:- Model (
Model
): The Eloquent model that defines the database table structure. - Repository to manage the model (
Repository
): Implements the repository pattern to encapsulate database access logic.
- Model (
- Option to Automated file generation
- Service for the repository (
Service
): Implements the business logic for the model. - Controller for the service (
Controller
): Defines API routes and uses the service for API logic. - Validation requests (
Request
): Validates input data for controller routes. - Seeder (
Seeder
): Populates the database with sample data for testing purposes. - Factory (
Factory
): Generates dummy data for testing purposes.
- Service for the repository (
- Predefined CRUD methods: The generated
Repository
,Service
andController
implement the standard methods of a RESTful API:create
: Create a new instance of the modelread
: Read a specific instance of the modelupdate
: Update an existing instance of the modeldelete
: Delete an instance of the modellist
: List all instances of the model
- Defining routes with Laravel Route Attributes: Use
spatie/laravel-route-attributes
to clearly and concisely define routes in the controller. For example:
php
#[Get(uri: 'models/{id}', name: 'models.read')]
public function read(string $id): JsonResponse
{
return response()->json($this->service->read($id));
}