zealous-creations / tranquil-model-controller
description
Requires
- inertiajs/inertia-laravel: >=0.6 <3.0
- laravel/framework: >=10.0 <13.0
- laravel/sanctum: >=3.0 <5.0
Requires (Dev)
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.0
- dev-master
- 0.10.45
- 0.10.44
- 0.10.43
- 0.10.42
- 0.10.41
- 0.10.40
- 0.10.39
- 0.10.38
- 0.10.37
- 0.10.36
- 0.10.35
- 0.10.34
- 0.10.33
- 0.10.32
- 0.10.31
- 0.10.30
- 0.10.29
- 0.10.28
- 0.10.27
- 0.10.26
- 0.10.25
- 0.10.24
- 0.10.23
- 0.10.22
- 0.10.21
- 0.10.20
- 0.10.19
- 0.10.18
- 0.10.17
- 0.10.16
- 0.10.15
- 0.10.14
- 0.10.13
- 0.10.12
- 0.10.11
- 0.10.10
- 0.10.9
- 0.10.8
- 0.10.7
- 0.10.6
- 0.10.5
- 0.10.4
- 0.10.3
- 0.10.2
- 0.10.1
- 0.10.0
- 0.9.11
- 0.9.10
- 0.9.9
- 0.9.8
- 0.9.7
- 0.9.6
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- dev-for-laravel-11
- dev-for-laravel-9
This package is auto-updated.
Last update: 2025-04-22 14:38:22 UTC
README
This package contains base Laravel Eloquent models and controllers that contain all the functionality you'll need for CRUD operations. Making Laravel development a more "Tranquil" experience.
Compatible with Laravel 10, 11, and 12
Install
Require it with composer
composer require zealous-creations/tranquil-model-controller
NOTE: If you have installed
inertiajs/inertia-laravel
lower thanv0.6
ordoctrine/dbal
lower thanv3.0
then you may need to remove them before requiringzealous-creations/tranquil-model-controller
composer remove inertiajs/inertia-laravel composer remove doctrine/dbal composer require zealous-creations/tranquil-model-controller
Publish migrations
There are 2 migrations in this package for creating a users
table and an attachments
table
If you want to modify these migrations be for running them, then run this artisan command:
php artisan vendor:publish --tag=tranquil-model-migrations
Usage
Tranquil Controller
The Tranquil Controller takes care of all the methods of a standard Laravel controller: index
, create
, show
, edit
, store
, and destroy
For any of your model controllers all you have to do is extend TranquilController
class CarController extends TranquilController {}
Then all you need to do is add the resource routes for the model.
// routes/web.php Route::resource('cars', CarController::class);
Now all of the endpoints for the resource routes will automatically work - without having to add any methods to your controller.
GET|HEAD cars .................. cars.index › CarController@index
POST cars .................. cars.store › CarController@store
GET|HEAD cars/create ......... cars.create › CarController@create
GET|HEAD cars/{car} .............. cars.show › CarController@show
PUT|PATCH cars/{car} .......... cars.update › CarController@update
DELETE cars/{car} ........ cars.destroy › CarController@destroy
GET|HEAD cars/{car}/edit ......... cars.edit › CarController@edit
Show Endpoint Example
GET /cars/1
{ "success": true, "message": "", "car": { "id": 1, "make": "Audi", "model": "A3", "year": 2016 } }
Update Endpoint Example
PATCH /cars/1 PAYLOAD {"year": 2024}
This will update year
column of the cars
record that has the id of 1
- As long as the year
is included in the $fillable
model parameter.
Or if you have the model extend TranquilModel
class Car extends TranquilModel { //... }
Store Endpoint Example
POST /cars PAYLOAD {"make": "Tesla", "model": "Model S", year": 2024}
This will create a new record in the cars
table. You can have automatic input validation if the model extends TranquilModel
or uses the HasValidation
trait.
class Car extends Model { use HasValidation; //... }
List Endpoint
There is also a list
route endpoint you can add for fetching a list of records for the model
// routes/web.php Route::post('cars/list', [CarController::class, 'list'])->name('cars.list');
Example
POST /cars/list PAYLOAD {"where": {"make": "Buick"}}
{ "success": true, "message": "", "total": 4, "records": [ { "id": 108, "make": "Buick", "model": "Enclave", "year": 2016 }, { "id": 109, "make": "Buick", "model": "Encore GX", "year": 2016 }, { "id": 110, "make": "Buick", "model": "Envision", "year": 2016 }, { "id": 111, "make": "Buick", "model": "Envista", "year": 2016 } ] }
Tranquil Inertia Controller
You can return Inertia responses for all the standard controller methods by extending the TranquilInertiaController
class CarController extends TranquilInertiaController {}
Now all of the endpoints will return an Inertia
response to the corresponding component path.
/cars .............. resources/js/Pages/Cars/Index
/cars/create ....... resources/js/Pages/Cars/CreateEdit
/cars/{car} ........ resources/js/Pages/Cars/Show
/cars/{car}/edit ... resources/js/Pages/Cars/CreateEdit
User Model
This package also comes with a TranquilUser
model that is for the authenticated user.
You can extend this model to modify it:
class User extends \Tranquil\Models\TranquilUser { public const roleOptions = [ [ 'handle' => 'super', 'name' => 'Super User', 'description' => 'Has full access', ], [ 'handle' => 'leader', 'name' => 'Leader', 'description' => 'Has administrator access', ], [ 'handle' => 'staff', 'name' => 'Staff', 'description' => 'Has basic access', ], ]; //... }