prowectcms / resources
1.0.0
2022-03-13 15:35 UTC
Requires
- illuminate/support: ^9.4
- spatie/laravel-query-builder: ^5.0
Requires (Dev)
- orchestra/testbench: ^7.1
- phpunit/phpunit: ^9.5
- sempro/phpunit-pretty-print: ^1.4
This package is auto-updated.
Last update: 2025-03-13 22:09:19 UTC
README
Laravel Resources & API Builder based on spatie/laravel-query-builder
Installation
composer require prowetcms/resources
Usage
Sample Repository:
<?php namespace App\Repositories; use App\Models\User; use ProwectCMS\Resources\Repository; use ProwectCMS\Resources\Fields\FieldDefinition; use ProwectCMS\Resources\Facades\Field; class UserRepository extends Repository { public function getModelClass() { return User::class; } public function getFieldDefinition() : FieldDefinition { return (new FieldDefinition) ->add(Field::make('id', ['name' => 'id'])) ->add(Field::make('text', ['name' => 'name'])->rules('required')) ->add(Field::make('email', ['name' => 'email'])) ; } }
Sample Controller:
<?php namespace App\Http\Controllers; use App\Repositories\UserRepository; use ProwectCMS\Resources\Http\Controllers\ApiResourceController; use ProwectCMS\Resources\Repository; class UserController extends ApiResourceController { protected function getRepository() : Repository { return new UserRepository(); } }
Sample Routes:
Route::apiResource('users', UserController::class);