PHPackages                             cyaoz94/laravel-utilities - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cyaoz94/laravel-utilities

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cyaoz94/laravel-utilities
=========================

This is a package for easily setting up laravel backend services.

1.4.3(4y ago)060MITPHPPHP ^7.4|^8.0

Since Mar 11Pushed 4y ago1 watchersCompare

[ Source](https://github.com/cyaoz94/laravel-utilities)[ Packagist](https://packagist.org/packages/cyaoz94/laravel-utilities)[ Docs](https://github.com/cyaoz94/laravel-utilities)[ RSS](/packages/cyaoz94-laravel-utilities/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (10)Used By (0)

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
------------

[](#installation)

Proceed to install the package via composer:

```
composer require cyaoz94/laravel-utilities:^1.0
```

Usage
-----

[](#usage)

### CrudController

[](#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.

```
// imports
use Cyaoz94\LaravelUtilities\CrudController;

class AdminUserController extends CrudController
{

    public function __construct(Request $request)
    {
        // let specify model class
        $this->modelClass = AdminUser::class;

        parent::__construct($request);
    }
    // your implementation here
}
```

### Filterable

[](#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.

```
// imports
use Cyaoz94\LaravelUtilities\Filters\Filterable;

class AdminUser extends Authenticatable
{
    // use Filterable trait
    use HasFactory, Filterable;
}
```

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()`

```
namespace Cyaoz94\LaravelUtilities\Filters;

class AdminUserFilter extends QueryFilter
{
    public function name($value)
    {
        parent::like('name', $value);
    }
}
```

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.

```
// imports
use Cyaoz94\LaravelUtilities\CrudController;
use Cyaoz94\LaravelUtilities\Filters\AdminUserFilter;

class AdminUserController extends CrudController
{

    public function __construct(Request $request)
    {
        $this->modelClass = AdminUser::class;
        // specify Filter class
        $this->filterClass = AdminUserFilter::class;

        parent::__construct($request);
    }

    // your implementation here
}
```

In certain scenarios, you will need to override the base functions of `CrudController`, you can still utilize the Filterable trait by doing the following

```
class AdminUserController extends CrudController
{
    // an overriding function in the child class
    public function index(Request $request)
    {
        $query = AdminUser::filter(new AdminUserFilter($request));

        // your implementations
    }
}
```

### Migrations

[](#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:

```
php artisan vendor:publish --provider="Cyaoz94\LaravelUtilities\LaravelUtilitiesServiceProvider" --tag="migrations"
```

Run the migrations to create `admin_users` table.

```
php artisan migrate
```

### Spatie Laravel Permission

[](#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:

```
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
```

Run the migrations to create all related tables.

```
php artisan migrate
```

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`.

```
protected $routeMiddleware = [
    'permission' => \Cyaoz94\LaravelUtilities\PermissionMiddleware::class,
];
```

You need to add PermissionMiddleware exception handling in `app/Exceptions/Handler.php`.

```
namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Spatie\Permission\Exceptions\UnauthorizedException as SpatieUnauthorizedException;
use Throwable;

class Handler extends ExceptionHandler
{
    public function render($request, Throwable $exception, $message = '')
    {
        if ($exception instanceof SpatieUnauthorizedException) {
            return response()->json(
                [
                    'code' => 401,
                    'error_message' => 'Unauthorized',
                ], 401
            );
        }
    }
}
```

Use middleware in your routes.

```
Route::get('', [AdminUserController::class, 'index'])->middleware('permission:admin-user.read');
```

### Seeders

[](#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:

```
php artisan vendor:publish --provider="Cyaoz94\LaravelUtilities\LaravelUtilitiesServiceProvider" --tag="seeders"
```

`RolePermissionSeeder` will seed basic permissions, create superadmin role, grant permissions to superadmin, and create one admin user as superadmin. Run the seeder via:

```
php artisan db:seed --class=RolePermissionSeeder
```

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.

```
$permissions = [
    'admin-user.create',
    'admin-user.read',
    'admin-user.update',
    'admin-user.delete',
    'user.create',
    'user.read',
    'user.update',
    'user.delete',
    'role.create',
    'role.read',
    'role.update',
    'role.delete',
];
```

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.

```
// database/seeders/RolePermissionSeeder.php

$guardName = 'sanctum';
```

```
// app/Models/AdminUser.php

namespace App\Models;

use Laravel\Sanctum\HasApiTokens;
use Cyaoz94\LaravelUtilities\Models\AdminUser as BaseAdminUser;

class AdminUser extends BaseAdminUser
{
    use HasApiTokens;

    protected $guard_name = 'sanctum';
}
```

### Role Features

[](#role-features)

To use role related features (example `RoleController`), please register RolePolicy in `AuthServiceProvider`.

```
namespace App\Providers;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Spatie\Permission\Models\Role;
use Cyaoz94\LaravelUtilities\Policies\RolePolicy;

class AuthServiceProvider extends ServiceProvider
{
    protected $policies = [
        Role::class => RolePolicy::class,
    ];

    public function boot()
    {
        $this->registerPolicies();
    }
}
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please contact your senior dev.

Credits
-------

[](#credits)

- Casper Ho

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

9

Last Release

1496d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/38554428?v=4)[Casper Ho](/maintainers/cyaoz94)[@cyaoz94](https://github.com/cyaoz94)

---

Top Contributors

[![cyaoz94](https://avatars.githubusercontent.com/u/38554428?v=4)](https://github.com/cyaoz94 "cyaoz94 (10 commits)")

---

Tags

Laravel Utilitiescyaoz94

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cyaoz94-laravel-utilities/health.svg)

```
[![Health](https://phpackages.com/badges/cyaoz94-laravel-utilities/health.svg)](https://phpackages.com/packages/cyaoz94-laravel-utilities)
```

###  Alternatives

[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)[mrmarchone/laravel-auto-crud

Laravel Auto CRUD helps you streamline development and save time.

28711.8k2](/packages/mrmarchone-laravel-auto-crud)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[omaralalwi/laravel-trash-cleaner

clean logs and debug files (clockwork , laravel telescope and more)

221.8k](/packages/omaralalwi-laravel-trash-cleaner)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
