Download the PHP package cyaoz94/laravel-utilities without Composer
On this page you can find all versions of the php package cyaoz94/laravel-utilities. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cyaoz94/laravel-utilities
More information about cyaoz94/laravel-utilities
Files in cyaoz94/laravel-utilities
Package laravel-utilities
Short Description This is a package for easily setting up laravel backend services.
License MIT
Homepage https://github.com/cyaoz94/laravel-utilities
Informations about the package laravel-utilities
Laravel Utilities
This is a package containing handy utils such as built-in authentication and authorization (Spatie Laravel Permissions), easy model filtering (Filtertable) setup, and easy CRUD API setup (CrudController).
Installation
Proceed to install the package via composer:
Usage
CrudController
You can extend our controller in order to use our base functions to speed up your CRUD api development. Just specify the model class in your constructor method and the CRUD methods defined in CrudController will know which model to query for.
Filterable
You can also use our Filterable trait so that you can easily implement filtering logic for your controller's CRUD methods.
First, use the trait in your model.
Define your filter class. Here we will define a name()
method to handle filtering for the name column.
Take note that the filter key should be always be in snake_case, eg. some_key
. The QueryFilter.php
class will loop through all the parameters in the request body to see if any matching method names in camelCase are found.
Using back our some_key
example, the matching function name will be someKey()
Then in your controller's constructor, specify which filter class to use. Now, name
's value submitted in the request
body will be used for filtering.
In certain scenarios, you will need to override the base functions of CrudController
,
you can still utilize the Filterable trait by doing the following
Migrations
The migrations of this package are now publishable under the "migrations" tag. It will publish the create_admin_users_table
migration in the migrations folder in the database path, prefixed with the current date and time via:
Run the migrations to create admin_users
table.
Spatie Laravel Permission
You can easily integrate spatie laravel permission using our package. You should publish the migration
and the config/permission.php
config file with:
Run the migrations to create all related tables.
You need to register our middleware in app/Http/Kernel.php
file. If you would like to override our middleware, you can create your new middleware and extend ours. Remember to register your middleware in app/Http/Kernel.php
.
You need to add PermissionMiddleware exception handling in app/Exceptions/Handler.php
.
Use middleware in your routes.
Seeders
The seeders of this package are now publishable under the "seeders" tag. It will publish the RolePermissionSeeder
seeder in the seeders folder in the database path via:
RolePermissionSeeder
will seed basic permissions, create superadmin role, grant permissions to superadmin, and create one admin user as superadmin. Run the seeder via:
In RolePermissionSeeder.php
, you can update permissions
array according to your system needs. We included some basic one. You can always run this seeder when you added or updated your permissions. It helps to update accordingly.
In RolePermissionSeeder.php
and Cyaoz94\LaravelUtilities\Models\AdminUser.php
, we defaulted $guardName = 'admin'
. You might want to change it to other guard name, example sanctum
.
You can create your own AdminUser
model and extends our model. You need to update the guard name in both RolePermissionsSeedeer.php
and AdminUser
model.
Role Features
To use role related features (example RoleController
), please register RolePolicy in AuthServiceProvider
.
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please contact your senior dev.
Credits
- Casper Ho
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
All versions of laravel-utilities with dependencies
illuminate/support Version ^8.0|^9.0
spatie/laravel-permission Version ^5.1