Download the PHP package lolaji/laravel-controller-trait without Composer
On this page you can find all versions of the php package lolaji/laravel-controller-trait. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download lolaji/laravel-controller-trait
More information about lolaji/laravel-controller-trait
Files in lolaji/laravel-controller-trait
Download lolaji/laravel-controller-trait
More information about lolaji/laravel-controller-trait
Files in lolaji/laravel-controller-trait
Vendor lolaji
Package laravel-controller-trait
Short Description A reuseable controller trait for laravel controller
License MIT
Package laravel-controller-trait
Short Description A reuseable controller trait for laravel controller
License MIT
Please rate this library. Is it a good library?
Informations about the package laravel-controller-trait
Laravel Controller Trait - A reuseable laravel controllers
Laravel Controller Trait is a Laravel reuseable package that helps you reduce the amount of logic you write for your laravel application.
Install Package
or add the package to your composer.json
Then, run
Usage
First create your controller, add ""use Lolaji\LaravelControllerTrait\LaravelControllerTrait"" trait
<?php
namespace App\HTTP;
class UserController extents Controller
{
use Lolaji\LaravelControllerTrait\LaravelControllerTrait;
protected $_model = User::class;
protected $_relation_models = ["profile", "posts"];
protected $_fillable = ["username", "email"];
protected $_profile_fillable = ["firstname", "lastname", "date_of_birth"];
protected $_result_filters = [
"active" => "=",
"status" => "="
...
];
protected function _validate_rules()
{
return [
"username" => ['required', 'string'],
"email" => ['required', 'string'],
...
];
}
// if you would like to serialize the fillable data
protected function _serialze_input(array $input): array
{
return $input;
}
protected _hook(Request $request, $model_result, $operation)
{
switch($opertion) {
case 'created':
// Code here execute after user is created
break;
case 'updated':
// Code here execute after user is updated
break;
case 'attach':
// Code here execute after attached
break;
case 'detach':
// Code here execute after detached
break;
case 'sync':
// Code here execute after synced
break;
case 'updateWithoutDetaching':
// Code here execute after updateWithoutDetaching
break;
case 'updateExistingPivot':
// Code here execute after updateExistingPivot
break;
case 'syncWithPivotValues':
// Code here execute after syncWithPivotValues
break;
case 'destroyed':
// Code here execute after user is destroy
break;
}
}
// Define the validation rule for the relationship profile
protected function _validate_profile_rule(): array
{
return [
"firstname" => ["string", "max:20"],
...
];
}
// if you would like to serialize the profile relationship fillable data
protected function _serialze_profile_input(array $input): array
{
return $input;
}
// Define the relationship "profile" hook
protected function _profile_hook(Request $request, $model, $operation)
{
// Perform code execution like in _hook method
}
}
All versions of laravel-controller-trait with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.0.1
The package lolaji/laravel-controller-trait contains the following files
Loading the files please wait ....