Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| CrudController | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | n/a |
0 / 0 |
|||
| modelClassName | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace DevToolbelt\LaravelFastCrud; |
| 6 | |
| 7 | use DevToolbelt\JsendPayload\AnswerTrait; |
| 8 | use DevToolbelt\LaravelFastCrud\Actions\Create; |
| 9 | use DevToolbelt\LaravelFastCrud\Actions\Delete; |
| 10 | use DevToolbelt\LaravelFastCrud\Actions\ExportCsv; |
| 11 | use DevToolbelt\LaravelFastCrud\Actions\Options; |
| 12 | use DevToolbelt\LaravelFastCrud\Actions\Read; |
| 13 | use DevToolbelt\LaravelFastCrud\Actions\Restore; |
| 14 | use DevToolbelt\LaravelFastCrud\Actions\Search; |
| 15 | use DevToolbelt\LaravelFastCrud\Actions\SoftDelete; |
| 16 | use DevToolbelt\LaravelFastCrud\Actions\Update; |
| 17 | use DevToolbelt\LaravelFastCrud\Traits\Helpers; |
| 18 | use Illuminate\Database\Eloquent\Model; |
| 19 | use Illuminate\Foundation\Validation\ValidatesRequests; |
| 20 | |
| 21 | /** |
| 22 | * Abstract base controller providing full CRUD operations for Eloquent models. |
| 23 | * |
| 24 | * This controller composes all CRUD action traits (Create, Read, Update, Delete, |
| 25 | * SoftDelete, Restore, Search, Options, ExportCsv) and provides hook methods |
| 26 | * for customization without overriding the entire action logic. |
| 27 | * |
| 28 | * Included Traits: |
| 29 | * - AnswerTrait: JSend response formatting |
| 30 | * - ValidatesRequests: Laravel validation support |
| 31 | * - Helpers: Utility methods (hasModelAttribute, runValidation) |
| 32 | * - Create, Read, Update, Delete, SoftDelete, Restore, Search, Options, ExportCsv: CRUD actions |
| 33 | * |
| 34 | * @example |
| 35 | * ```php |
| 36 | * class ProductController extends CrudController |
| 37 | * { |
| 38 | * protected function modelClassName(): string |
| 39 | * { |
| 40 | * return Product::query()->class; |
| 41 | * } |
| 42 | * |
| 43 | * protected function createValidateRules(): array |
| 44 | * { |
| 45 | * return [ |
| 46 | * 'name' => ['required', 'string', 'max:255'], |
| 47 | * 'price' => ['required', 'numeric', 'min:0'], |
| 48 | * ]; |
| 49 | * } |
| 50 | * |
| 51 | * protected function beforeCreateFill(array &$data): void |
| 52 | * { |
| 53 | * $data['created_by'] = auth()->id(); |
| 54 | * } |
| 55 | * } |
| 56 | * ``` |
| 57 | */ |
| 58 | abstract class CrudController |
| 59 | { |
| 60 | use AnswerTrait; |
| 61 | use ValidatesRequests; |
| 62 | use Helpers; |
| 63 | use Create; |
| 64 | use Read; |
| 65 | use Update; |
| 66 | use Delete; |
| 67 | use SoftDelete; |
| 68 | use Restore; |
| 69 | use Search; |
| 70 | use Options; |
| 71 | use ExportCsv; |
| 72 | |
| 73 | /** |
| 74 | * Returns the fully qualified class name of the Eloquent model. |
| 75 | * |
| 76 | * @return class-string<Model> The model class name |
| 77 | */ |
| 78 | abstract protected function modelClassName(): string; |
| 79 | } |