leandrowkz / laravel-basis
Laravel Basis is a package that provides a base service layer to your application, containing CRUD operations.
Installs: 746
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^7.3
- laravel/framework: ^7.0
Requires (Dev)
- fzaninotto/faker: 1.9.1
- mockery/mockery: 1.4.0
- orchestra/testbench: 5.3.0
README
Laravel Basis is a package that provides a base CRUD layer for your application.
Leandrowkz\Basis\Controllers\BaseController
Leandrowkz\Basis\Services\BaseService
Leandrowkz\Basis\Traits\AccessibleProps
Leandrowkz\Basis\Traits\MutatesProps
These classes provides an easy way to CRUD operations inside Laravel apps. All you have to do is to extend and configure your classes from those available here.
Leandrowkz\Basis\Controllers\BaseController
Every class extended from BaseController must set the $service
and $request
(for validation) class names strings (Ex: FooService::class).
protected $service; protected $request; public function all(); public function find(string $id); public function create(array $data); public function update(string $id, array $data); public function delete(string $id); public function exists($id); public function validate(); public function service(BaseServiceInterface $service = null);
Leandrowkz\Basis\Service\BaseService
Every class exteded from BaseService must set $model
class name string (Ex: FooModel::class). The create/update operations are done by using de $fillable
array presented on $model
class.
protected $model; public function all(); public function find(string $id); public function query($where); public function create(array $data); public function update(string $id, array $data); public function delete(string $id); public function model(string $model = null);
Leandrowkz\Basis\Traits\AccessibleProps
This trait adds to the target class fluent getters/setters to access any property through a method with same name. As a caveat it breaks any property visibility.
protected $foo = 1; protected $bar = 2; $this->foo(); // returns 1; $this->bar(); // returns 2; $this->foo(3); // sets $this->foo as 3; $this->bar(3); // sets $this->bar as 3;
Leandrowkz\Basis\Traits\MutatesProps
This trait adds a method that fetch all class properties and transforms all props with valid class names into objects of same class. Ex:
protected $customService = MyService::class; // string $this->customService; // string $this->mutateProps(); $this->customService; // MyService object
License
This code is published under the MIT License. This means you can do almost anything with it, as long as the copyright notice and the accompanying license file is left intact.
Contributing
Feel free to send pull requests or create issues if you come across problems or have great ideas. Any input is appreciated!