Quick Start
Introduction
This package provides a ready-to-use base controller and model to implement standard CRUD with minimal boilerplate.
Steps
- Create a model extending TranquilModel (or use HasValidation on your own Eloquent model):
1use Tranquil\Models\TranquilModel;
2
3class Car extends TranquilModel {
4 protected $table = 'cars';
5 protected $fillable = ['make', 'model', 'year'];
6}
- Create a controller extending TranquilController:
1use Tranquil\Controllers\TranquilController;
2
3class CarController extends TranquilController {}
- Add resource routes:
1use Illuminate\Support\Facades\Route;
2
3Route::resource('cars', CarController::class);
- Optional: Add a list endpoint for easy filtered lists
1Route::get('cars-list', [CarController::class, 'list']);
That’s it. Endpoints work out-of-the-box:
- GET /cars (index)
- GET /cars/create (create)
- POST /cars (store)
- GET /cars/{car} (show)
- GET /cars/{car}/edit (edit)
- PATCH/PUT /cars/{car} (update)
- DELETE /cars/{car} (destroy)
Validation
- TranquilModel includes HasValidation. Override getValidationRules() and getDefaultValidationAttributes() as needed.
Relations
- ModelController handles syncing belongsTo, hasOne, hasMany, belongsToMany, morphOne, morphMany, morphToMany when you pass nested arrays in your request payload. See controllers.md for the expected shapes.