PHPackages                             yaangvu/laravel-base - 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. [API Development](/categories/api)
4. /
5. yaangvu/laravel-base

ActiveLibrary[API Development](/categories/api)

yaangvu/laravel-base
====================

Laravel API Resource Base

v4.1.3(1y ago)711.5k1[1 PRs](https://github.com/YaangVu/Laravel-Base/pulls)5MITPHPPHP ^8.1|^8.2

Since Apr 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/YaangVu/Laravel-Base)[ Packagist](https://packagist.org/packages/yaangvu/laravel-base)[ RSS](/packages/yaangvu-laravel-base/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (7)Dependencies (5)Versions (159)Used By (5)

Laravel Base Package
====================

[](#laravel-base-package)

This base will help to create simple API (CRUD) for 1 specific entity

Install
-------

[](#install)

```
composer require yaangvu/laravel-base
```

### For Laravel

[](#for-laravel)

Publish configuration file and Base Classes

```
php artisan vendor:publish --provider="YaangVu\LaravelBase\Providers\BaseServiceProvider"
```

### For lumen

[](#for-lumen)

```
cp vendor/yaangvu/laravel-base/src/config/laravel-base.php config/laravel-base.php
mkdir -p app/Base
cp vendor/yaangvu/laravel-base/src/Base/Publish/Controller.php app/Base/Controller.php
cp vendor/yaangvu/laravel-base/src/Base/Publish/Service.php app/Base/Service.php
```

Generator Command
-----------------

[](#generator-command)

If you want to use Generator Command, Add the following class to the `providers` array in `config/app.php`:

```
  YaangVu\LaravelBase\Provider\GeneratorServiceProvider::class,
```

If you want to manually load it only in non-production environments, instead you can add this to your `AppServiceProvider` with the `register()` method:

```
  public function register()
  {
      if ($this->app->isLocal()) {
          $this->app->register(\YaangVu\LaravelBase\Provider\GeneratorServiceProvider::class);
      }
      // ...
  }
```

Initial API resource
--------------------

[](#initial-api-resource)

### Generate code

[](#generate-code)

```
php artisan yaangvu:base Post
```

Option:

- -S: generate code with default Swagger annotation
- -i: Auto inject Service in Controller methods

### Directory structure of generated code

[](#directory-structure-of-generated-code)

```
├── app
│   ├── Domains
│   │   └── Post
│   │       ├── Controllers
│   │       │   └── PostController.php
│   │       ├── Models
│   │       │   └── Post.php
│   │       └── Services
│   │           └── PostService.php

```

### Route

[](#route)

```
Route::base('/posts', \App\Domains\Post\Controllers\PostController::class);
```

Usage
-----

[](#usage)

### Dynamic query parameters

[](#dynamic-query-parameters)

#### Operators supported

[](#operators-supported)

```
$operators
        = [
            '__gt' => OperatorConstant::GT, // Greater than
            '__ge' => OperatorConstant::GE, // Greater than or equal
            '__lt' => OperatorConstant::LT, // Less than
            '__le' => OperatorConstant::LE, // Less than or equal
            '__~'  => OperatorConstant::LIKE // Like
        ];

```

#### To query, you can add more params with format:

[](#to-query-you-can-add-more-params-with-format)

`{param-name}{operator} = {value}`

#### Example:

[](#example)

1. `username = admin` ----&gt; `username` equal `admin`
2. `name__~ = super` ----&gt; `name` like `%super%`
3. `age__gt = 18` ----&gt; `age` gather than `18`

#### Full request example

[](#full-request-example)

Request to query user with `username=admin` and `name LIKE %super%` and `age > 18`

```
curl --location --request GET 'http://localhost:8000/api/v1/users?username=admin&name__~=super&age__gt=18'

```

### Validate before Add an entity

[](#validate-before-add-an-entity)

Support full Laravel validation: [Validation](https://laravel.com/docs/master/validation)

```
class UserService extends BaseService
{
    public function storeRequestValidate(object $request, array $rules = []): bool|array
    {
        $rules = [
            'username' => 'required|max:255|unique:users',
        ];

        return parent::storeRequestValidate($request, $rules);
    }
}

```

### Validate before Update an entity

[](#validate-before-update-an-entity)

Support full Laravel validation: [Validation](https://laravel.com/docs/master/validation)

```
class UserService extends BaseService
{
    public function updateRequestValidate(int|string $id, object $request, array $rules = []): bool|array
    {
        $rules = [
            'username' => 'required|max:255|unique:users,id',
        ];

        return parent::updateRequestValidate($id, $request, $rules);
    }
}

```

### Service Observe

[](#service-observe)

It supports these observe function:

1. `function postAdd()`
2. `function postUpdate()`
3. `function postDelete()`
4. `function postGet()`
5. `function postGetAll()`

### Cache data

[](#cache-data)

If you want to cache data when `create` `update` `select`, implement `ShouldCache` interface

```
class UserService extends BaseService implements \YaangVu\LaravelBase\Base\Contract\ShouldCache
{}
```

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance40

Moderate activity, may be stable

Popularity27

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 79.9% 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 ~9 days

Recently: every ~83 days

Total

148

Last Release

563d ago

Major Versions

v1.1.45 → v2.0.32021-10-25

v1.1.x-dev → v3.0.02022-09-02

v2.2.1 → v3.0.52022-09-16

v2.x-dev → v3.0.62022-09-23

v3.0.12 → v4.0.02023-02-28

PHP version history (7 changes)v1.0.0PHP ^8.0

v1.0.2PHP ^7.4|^8.0

v2.1.0PHP ^8.1

v2.1.4PHP ^8.1|^8.0

v2.1.5PHP ^8.0|^8.1

v1.1.46PHP ^8.0,^8.1

v3.0.0PHP ^8.1|^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/fc6edb5366277d97ecfedc77bcfbf41f49be74ccb182f6c2d04e597640d0c15c?d=identicon)[YaangVu](/maintainers/YaangVu)

---

Top Contributors

[![YaangVu](https://avatars.githubusercontent.com/u/14012135?v=4)](https://github.com/YaangVu "YaangVu (135 commits)")[![keyhoang](https://avatars.githubusercontent.com/u/83800649?v=4)](https://github.com/keyhoang "keyhoang (16 commits)")[![ChuDanh](https://avatars.githubusercontent.com/u/122071966?v=4)](https://github.com/ChuDanh "ChuDanh (10 commits)")[![giangvt-toprate](https://avatars.githubusercontent.com/u/53530238?v=4)](https://github.com/giangvt-toprate "giangvt-toprate (4 commits)")[![hoangky1705](https://avatars.githubusercontent.com/u/75289478?v=4)](https://github.com/hoangky1705 "hoangky1705 (3 commits)")[![NguyenDuyNam29032002](https://avatars.githubusercontent.com/u/114595192?v=4)](https://github.com/NguyenDuyNam29032002 "NguyenDuyNam29032002 (1 commits)")

---

Tags

apilaravelswaggergeneratorlumenbaseyaangvu

### Embed Badge

![Health badge](/badges/yaangvu-laravel-base/health.svg)

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

###  Alternatives

[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k13.5M59](/packages/knuckleswtf-scribe)[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k36.4M126](/packages/darkaonline-l5-swagger)[darkaonline/swagger-lume

OpenApi or Swagger integration to Lumen

3322.4M3](/packages/darkaonline-swagger-lume)[infyomlabs/swagger-generator

Swagger Generator for InfyOm Laravel Generator

1141.1M5](/packages/infyomlabs-swagger-generator)[davmixcool/lumen-apidoc-generator

Generate beautiful API documentation using Dingo router from your Lumen application

173.1k](/packages/davmixcool-lumen-apidoc-generator)

PHPackages © 2026

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