PHPackages                             samchentw/common - 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. [Database &amp; ORM](/categories/database)
4. /
5. samchentw/common

ActiveLibrary[Database &amp; ORM](/categories/database)

samchentw/common
================

4.1.0(3y ago)0227[1 issues](https://github.com/samchentw/common/issues)1MITPHPPHP ^7.4|^8.0

Since Sep 4Pushed 2y agoCompare

[ Source](https://github.com/samchentw/common)[ Packagist](https://packagist.org/packages/samchentw/common)[ RSS](/packages/samchentw-common/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (16)Used By (1)

Common
======

[](#common)

[![Latest Version on Packagist](https://camo.githubusercontent.com/692ccaf6f2432d0bbe84d661175df59dd01f25baa04c833008168914079db9f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616d6368656e74772f636f6d6d6f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/samchentw/common)[![tests](https://github.com/samchentw/common/actions/workflows/tests.yml/badge.svg)](https://github.com/samchentw/common/actions/workflows/tests.yml)
1.repository pattern
2.quickly make repository,service and helper
3.simple dictionary type
4.make simple router list

Installation
------------

[](#installation)

`composer require samchentw/common`

Laravel
-------

[](#laravel)

Publish the config file by running:

```
$ php artisan vendor:publish --provider="Samchentw\Common\CommonServiceProvider"
```

Feature
-------

[](#feature)

Samchentw\\Common\\Repositories\\Base\\Repository
Samchentw\\Common\\Helpers\\DictionaryHelper
Samchentw\\Common\\Traits\\Supports\\HasEnable
Samchentw\\Common\\Traits\\Supports\\HasSort

Generate repository
-------------------

[](#generate-repository)

```
$ php artisan make:repository MyRepository
```

Generate service
----------------

[](#generate-service)

```
$ php artisan make:service MyService
```

Generate helper
---------------

[](#generate-helper)

```
$ php artisan make:helper MyHelper
```

Use Enable
----------

[](#use-enable)

In the migration. use ( $table-&gt;setEnable();)

```
    public function up()
    {
        Schema::create('articles', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->softDeletes();
            $table->setEnable();
            $table->timestamps();
        });
    }
```

In the model.

```
    namespace App\Models;

    use Illuminate\Database\Eloquent\Factories\HasFactory;
    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Database\Eloquent\SoftDeletes;
    use Samchentw\Common\Traits\Supports\HasEnable;

    class Article extends Model
    {
        use HasFactory,
            SoftDeletes,
            HasEnable;
```

Use Sort
--------

[](#use-sort)

In the migration. use ( $table-&gt;setSort();)

```
    public function up()
    {
        Schema::create('articles', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->softDeletes();
            $table->setSort();
            $table->timestamps();
        });
    }
```

In the model.

```
    namespace App\Models;

    use Illuminate\Database\Eloquent\Factories\HasFactory;
    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Database\Eloquent\SoftDeletes;
    use Samchentw\Common\Traits\Supports\HasSort;

    class Article extends Model
    {
        use HasFactory,
            SoftDeletes,
            HasSort;
```

You can set the sorting method in the config/common.php

Use Sort Or Enable in Controller
--------------------------------

[](#use-sort-or-enable-in-controller)

For example, make ArticleRepository,

```
$ php artisan make:repository ArticleRepository
```

```
    namespace App\Repositories;

    use Samchentw\Common\Repositories\Base\Repository;
    use App\Models\Article;

    class ArticleRepository extends Repository
    {

        /**
         * @return string
         */
        public function model(): string
        {
            return Article::class;
        }

    }
```

In Controller

```
    class ArticleController extends Controller
    {

        private $articleRepository;
        public function __construct(ArticleRepository $ArticleRepository)
        {
            $this->articleRepository = $ArticleRepository;
        }

        //for Front
        public function example1()
        {
            // get enable true data And sorted
            return $this->articleRepository->getAllForFront();
        }

        //for Front
        public function example2()
        {
            $query = $this->articleRepository->getAllForFrontQuery();
            // get enable true data And sorted
            return $query->where('title','=','test')->get();
        }

        //for Admin
        public function example3()
        {
            // get sorted data
            return $this->articleRepository->getAllForAdmin();
        }

        //for Admin
        public function example4()
        {
            $query = $this->articleRepository->getAllForAdminQuery();
            //  get sorted data
            return $query->where('title','=','test')->get();
        }

        //else...
        public function example5()
        {
            return Article::whereIn('id',[1,2,3,4,5])->orderBy('name')->sortByConfig()->get()
        }
```

DictionaryHelper
----------------

[](#dictionaryhelper)

use Samchentw\\Common\\Helpers\\DictionaryHelper;

```
    $datas = [
                [
                    "id" => 1,
                    "name" => "sam",
                    "job" => "developer"
                ],
                [
                    "id" => 2,
                    "name" => "john",
                    "job" => "admin"
                ],
                [
                    "id" => 3,
                    "name" => "vivian",
                    "job" => "user"
                ]
    ];

    $result1 = DictionaryHelper::toDictionary($datas, 'name', 'job');
    $result2 = DictionaryHelper::toDictionary($datas, 'id');

    //output:
     $result1 = [
         "sam" => "developer",
         "john" => "admin",
         "vivian" => "user"
     ];

     $result2 = [
         1 => [
                "id" => 1,
                "name" => "sam",
                "job" => "developer"
         ],
         2 => [
                "id" => 2,
                "name" => "john",
                "job" => "admin"
         ],
         3 => [
                "id" => 3,
                "name" => "vivian",
                "job" => "user"
         ]
     ];
```

Make Router List
----------------

[](#make-router-list)

```
$ php artisan output:router-list
```

url:

show method setting in config/common.php.

For Example:

```
    // config/common.php
    return [

        "model_sort" => env('MODEL_SORT', 'asc'),

        /**
         *  If you just want to show GET method.
         *  Run:
         *  php artisan optimize
         *  php artisan output:router-list
         **/
        "router_list_methods" => [
            "GET",
            // "HEAD",
            // "POST",
            // "PUT",
            // "PATCH",
            // "DELETE"
        ]
    ];
```

[![image](https://user-images.githubusercontent.com/89454932/136780164-bb3c0b89-ccdc-43fa-ab88-1a3f721badd2.png)](https://user-images.githubusercontent.com/89454932/136780164-bb3c0b89-ccdc-43fa-ab88-1a3f721badd2.png)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 82.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 ~30 days

Recently: every ~86 days

Total

15

Last Release

1299d ago

Major Versions

1.0.3 → 2.0.02021-09-08

2.5.0 → 4.0.02022-03-01

PHP version history (3 changes)1.0.0PHP ^7.4.20

1.0.3PHP ^7.3|^8.0

4.0.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/89454932?v=4)[samchentw](/maintainers/samchentw)[@samchentw](https://github.com/samchentw)

---

Top Contributors

[![samchentw](https://avatars.githubusercontent.com/u/89454932?v=4)](https://github.com/samchentw "samchentw (34 commits)")[![samchenwater](https://avatars.githubusercontent.com/u/43718347?v=4)](https://github.com/samchenwater "samchenwater (7 commits)")

---

Tags

eloquentlaravelmodel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/samchentw-common/health.svg)

```
[![Health](https://phpackages.com/badges/samchentw-common/health.svg)](https://phpackages.com/packages/samchentw-common)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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