PHPackages                             lagumen/laravel-essentials - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. lagumen/laravel-essentials

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

lagumen/laravel-essentials
==========================

Laravel package that contains essential utilities in building a small to large scale projects

v1.5(5y ago)1267MITPHPPHP ^7.4

Since Sep 4Pushed 5y ago1 watchersCompare

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

READMEChangelog (7)Dependencies (3)Versions (9)Used By (0)

Laravel Essentials
==================

[](#laravel-essentials)

This package provides utilities that can help you build a small to large scale projects.

Inspired by [Laravel Query Filters](https://github.com/ambengers/laravel-query-filter)

[![Build Status](https://camo.githubusercontent.com/bde617f4b667894257a00f37d2e177adb64db82cea3367f45657cb4816913033/68747470733a2f2f7472617669732d63692e636f6d2f72616c70686c6167756d656e2f6c61726176656c2d657373656e7469616c732e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/ralphlagumen/laravel-essentials)[![StyleCI](https://camo.githubusercontent.com/c08d66f03729fe162106a33bd00589290b83ebffdebbd253de837eb7b6d71919/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3239323732393937322f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/292729972?branch=master)

Features
========

[](#features)

This package allows you to create `Repositories`, `Actions`, `Validations` Class. It also features search, filtering and sorting functionality for your eloquent models.

Installation
============

[](#installation)

Run the following command inside your project.

```
composer require lagumen/laravel-essentials

```

Optionally you can publish the config file by running the following command.

```
php artisan vendor:publish --tag=laravel-essential-config

```

The config file contains the default namespace for `Actions`, `Validations`, `Repositories` and `Filters`. You can change the default namespace depending on your preference.

Usage
=====

[](#usage)

Repositories
------------

[](#repositories)

You can create your Repository Class by running the following command.

```
php artisan make:essential-repository UserRepository

```

This will create an Repository Class on `App\Repositories` by default.

```
use Lagumen\LaravelEssential\Concerns\LaravelEssentialRepository;
use Lagumen\LaravelEssential\Interfaces\LaravelEssentialRepositoryInterface;
use Lagumen\LaravelEssential\LaravelEssentialSearchableModel;
use App\Models\User;

class UserRepository extends LaravelEssentialRepository implements LaravelEssentialRepositoryInterface
{
    public function __construct(User $model)
    {
        $this->model = $model;
    }

    // We will use this later. ;)
    public function getAllFilteredUsers(array $filters = [])
    {
        return $this->model->query()->filter($filters);
    }

    public function createUser(array $data)
    {
        /** @var User $user */
        $user = $this->create($data);

        $user->setting()->create(['timezone' => $data['timezone'] ?? 'UTC']);

        return $user->load('setting');
    }
}

```

To apply this, just go ahead and initialize your Repository Class to your Controller.

```
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use App\Repositories\UserRepository;

class UsersController extends Controller
{
    protected $repository;

    public function __construct(UserRepository $repository)
    {
        $this->repository = $repository;
    }

    public function index(Request $request)
    {
        $users = $this->repository->getAllFilteredUsers($request->all());

        return response()->json($users);
    }

    public function store(Request $request)
    {
        $user = $this->repository->createUser($request->all());

        return response()->json($user);
    }
}

```

Validations
-----------

[](#validations)

Of course, you need to validate your request before inserting or updating a data in your database.

You can make your validation class by running the following command.

```
php artisan make:essential-validation UserValidation

```

This will create a Validation Class on `App\Http\Validations` by default.

```
use Lagumen\LaravelEssential\Interfaces\LaravelEssentialValidationInterface;

class UserValidation implements LaravelEssentialValidationInterface
{
    public function save(array $data = [])
    {
        return [
            'name'  => 'required|string',
            'email' => 'required|unique:users,email',
        ];
    }

    public function update(array $data = [])
    {
        return [
            'name'  => 'sometimes|string',
            'email' => 'sometimes|unique:users,email,'.$data['id'], // ignore self
        ];
    }
}

```

To apply this, just go ahead and call the `Validator` Facade inside your controller.

```
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Validator;
use App\Http\Validations\UserValidation;
use App\Repositories\UserRepository;

class UsersController extends Controller
{
  protected $validations;

  protected $repository;

  public function __construct(UserValidation $validation, UserRepository $repository)
  {
      $this->validations = $validation;
      $this->repository = $repository;
  }

  public function store(Request $request)
  {
      Validator::make($request->all(), $this->validations->save())->validate();

      $user = $this->repository->createUser($request->all());

      return response()->json($user);
  }

  public function update(Request $request, $id)
  {
      $data = $request->all();

      Validator::make($data, $this->validations->update($data))->validate();

      $user = $this->repository->updateById($id, $request->all());

      return response()->json($user);
  }
}

```

No need to create multiple Request Class for a single controller.

Actions
-------

[](#actions)

You can create your Action Class by running the following command.

```
php artisan make:essential-action UserTypeAction

```

This will create an Action Class on `App\Actions` by default.

```
use Lagumen\Essential\Interfaces\LaravelEssentialActionInterface;
use App\Models\User;

class UserTypeAction implements LaravelEssentialActionInterface
{
    protected $user;

    public function __construct(User $user)
    {
        $this->user = $user;
    }
    /**
     * Execute action
     *
     * @param  array  $data
     * @return mixed
     */
    public function execute(array $data = [])
    {
        if ($this->user->isAdmin()) {
           // do logic here...
        }

        if ($this->user->isEmployee()) {
           // do logic here...
        }
    }
}

```

This will help you, make your controller to be managable and to look cleaner.

```
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use App\Actions\UserTypeAction;

class UsersController extends Controller
{
  public function store(Request $request)
  {
      // Instead of doing this..
      if ($user->isAdmin()) {
         // do logic here...
      }

      if ($user->isEmployee()) {
         // do logic here...
      }

      // Try doing this..
      app(UserTypeAction::class, ['user' => $user])->execute();

      return response()->json($user);
  }
}

```

Filters
-------

[](#filters)

To allow your app to filter, search or sort data, just follow this guides..

First, let's create our Filter. You can do that by running the following command.

```
php artisan make:essential-filter User/Active

```

Notice that I used forward slash, this will create a class on `App\Filters\User\Active.php`.

```
use Illuminate\Database\Eloquent\Builder;

class Active
{
    /**
     * Handle filtering.
     *
     * @param Illuminate\Database\Eloquent\Builder $builder
     * @param string|null                          $value
     *
     * @return Illuminate\Database\Eloquent\Builder
     */
    public function __invoke(Builder $builder, $value)
    {
        return !$value
            ? $builder
            : $builder->where('active', $value);
    }
}

```

Next, let's apply the `CanPerformSearch` trait on the model that you want to allow searching and set the columns that you want to allow to be searched, by calling `$searchableColumns`.

```
use Illuminate\Database\Eloquent\Model;
use Lagumen\LaravelEssential\Concerns\CanPerformSearch;

class User extends Model
{
    use CanPerformSearch;

    /**
     * The attributes that are guarded.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'email',
    ];

    protected $searchableColumns = [
        'name',
        'setting' => ['timezone'] // this will allow searching of timezone on user setting.
    ];

    public function setting()
    {
        return $this->hasOne(UserSetting::class, 'user_id');
    }
}

```

You also need to call `filter` scope on your model. You can do that by doing this.

```
return User::withTrashed()->filter($arrayOfFilters);

```

Or, you can check what I did on the [Repositories](https://github.com/ralphlagumen/laravel-essentials#repositories) above. ;)

Now, you can perform filtering, searching and sorting by passing a request parameters to url:

```
/users?sort=id|desc&search=John&active=1

```

Package that I used before that is worth mentioning
---------------------------------------------------

[](#package-that-i-used-before-that-is-worth-mentioning)

[Laravel Fuse](https://github.com/exylon/laravel-fuse)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

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 ~17 days

Recently: every ~26 days

Total

7

Last Release

1967d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ee2345f84c5e35064e537b7162949bc758b84017e3e2f3cbab15a5f28d45471?d=identicon)[ralphlagumen](/maintainers/ralphlagumen)

---

Top Contributors

[![ralphlagumen](https://avatars.githubusercontent.com/u/16839236?v=4)](https://github.com/ralphlagumen "ralphlagumen (23 commits)")

---

Tags

laravelvalidationrepositoryactionessential

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lagumen-laravel-essentials/health.svg)

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

###  Alternatives

[schuppo/password-strength

This package provides a validator for ensuring strong passwords in Laravel 4 applications.

1432.7M1](/packages/schuppo-password-strength)[stuyam/laravel-phone-validator

A phone validator for Laravel using the free Twilio phone lookup service.

2861.3k](/packages/stuyam-laravel-phone-validator)[skysplit/laravel5-intl-translation

Laravel 5 package for better translation syntax using php-intl extension

10106.2k](/packages/skysplit-laravel5-intl-translation)[pacerit/laravel-polish-validation-rules

Simple Polish Validation rules for Laravel and Lumen framework

1449.9k](/packages/pacerit-laravel-polish-validation-rules)[laravel-validation-rules/ip

Validate if an ip address is public or private.

1729.7k](/packages/laravel-validation-rules-ip)[cohensive/validation

Extra functionality for Laravel 5 Validator.

1513.9k](/packages/cohensive-validation)

PHPackages © 2026

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