承接 cebpereira/layers 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cebpereira/layers

Composer 安装命令:

composer require cebpereira/layers

包简介

A laravel package to generate files for layered architecture

README 文档

README

A laravel package to generate files for layered architecture and automate interface bindings.

Recommended Laravel version: ^12.0

Go to Laravel Docs to see support policy.

Summary

Requirements

"php": "^8.2"
"symfony/finder": "^6.3 || ^7.0"
"illuminate/support": "^9.0 || ^10.20 || ^11.0 || ^12.0"
"illuminate/console": "^9.0 || ^10.20 || ^11.0 || ^12.0"

Installation

composer require cebpereira/layers --dev

Configuration

php artisan vendor:publish --tag=layers

This command will copy Layers config to your project config folder

<?php

return [

    'namespace' => [
        'repositories' => 'Repositories',
        'services' => 'Services',
    ],

    'path' => [
        'models' => app_path('Models'),
        'repositories' => app_path('Repositories'),
        'services' => app_path('Services'),
    ]
];

Into this file, you can switch the services/repositories default path. For this, keep the namespace and path keys both equals.

Usage

Using the layers artisan command, we can be generate files for repositories (interface and eloquent) and services.

php artisan layers + {option} + {model name}

Available options:

  • -e or --eloquent : Generate a repository eloquent for the model
  • -i or --interface : Generate a repository interface for the model
  • -s or --service : Generate a service for the model
  • -r or --repository : Generate a repository interface and eloquent for the model
  • -a or --all : Generate a service, repository interface and repository eloquent for the model
  • --wr : Specify the service's repositories

Subcommands

  • php artisan layers:repository --eloquent : the same as php artisan layers --eloquent
  • php artisan layers:repository --interface : the same as php artisan layers --interface
  • php artisan layers:service : the same as php artisan layers --service
  • php artisan layers:binds : List all binds from application
  • php artisan layers:scaffold : Scaffold repositories and services for all models

Generate Layers

php artisan layers --all User

This command will generate 3 files:

  • app/Repositories/UserRepositoryInterface.php
  • app/Repositories/UserRepositoryEloquent.php
  • app/Services/UserService.php

Structure Folder

UserRepositoryInterface.php

<?php

declare(strict_types=1);

namespace App\Repositories;

use App\Models\User;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Collection as SupportCollection;

interface UserRepositoryInterface
{
    public function __construct(User $user);

    /**
     * Stores a new instance of User in the database
     * @param SupportCollection|array|int|string $data
     * @return User
     */
    public function store(SupportCollection|array|int|string $data): User;

    /**
     * Returns all instances of User from the database
     * @param array|string $columns
     * @param array<array>|null $filters
     * @return Collection<int, User>
     */
    public function getList(array|string $columns = ['*'], ?array $filters = null): Collection;

    /**
     * Returns an instance of User from the given id
     * @param int|string $id
     * @return User|null
     */
    public function get(int|string $id): ?User;

    /**
     * Updates the data of an instance of User
     * @param SupportCollection|array|int|string $data
     * @param int|string $id
     * @return User
     */
    public function update(SupportCollection|array|int|string $data, int|string $id): User;

    /**
     * Removes an instance of User from the database
     * @param int|string $id
     * @return bool
     */
    public function destroy(int|string $id): bool;
}

UserRepositoryEloquent.php

<?php

declare(strict_types=1);

namespace App\Repositories;

use App\Models\User;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Collection as SupportCollection;

class UserRepositoryEloquent implements UserRepositoryInterface
{
    public function __construct(
        protected User $user,
    ) {}

    /**
     * Stores a new instance of User in the database
     * @param SupportCollection|array|int|string $data
     * @return User
     */
    public function store(SupportCollection|array|int|string $data): User
    {
        return $this->user->create($data);
    }

    /**
     * Returns all instances of User from the database
     * @param array|string $columns
     * @param array<array>|null $filters
     * @return Collection<int, User>
     */
    public function getList(array|string $columns = ['*'], ?array $filters = null): Collection
    {
        $query = $this->user->newQuery();

        if ($filters) {
            $query->where($filters);
        }

        return $query->get($columns);
    }

    /**
     * Returns an instance of User from the given id
     * @param int|string $id
     * @return User|null
     */
    public function get(int|string $id): ?User
    {
        return $this->user->find($id);
    }

    /**
     * Updates the data of an instance of User
     * @param SupportCollection|array|int|string $data
     * @param int|string $id
     * @return User
     */
    public function update(SupportCollection|array|int|string $data, int|string $id): User
    {
        $user = $this->user->findOrFail($id);
        $user->update($data);

        return $user;
    }

    /**
     * Removes an instance of User from the database
     * @param int|string $id
     * @return bool
     */
    public function destroy(int|string $id): bool
    {
        return (bool) $this->user->findOrFail($id)->delete();
    }
}

UserService.php

<?php

declare(strict_types=1);

namespace App\Services;

use App\Repositories\UserRepositoryInterface;

class UserService
{
    public function __construct(
        protected UserRepositoryInterface $repoUser,
    ) {}

    // Add your functions here...
}

Generate Layers with Subfolders

php artisan layers --repository User.Address

This command will generate 2 files:

  • app/Repositories/User/AddressRepositoryInterface.php
  • app/Repositories/User/AddressRepositoryEloquent.php

Structure Folder with Subfolders

Generate Services with more than one repository

php artisan layers --service --wr=Address --wr=User Person

This command will generate the follow file:

<?php

declare(strict_types=1);

namespace App\Services;

use App\Repositories\UserRepositoryInterface;
use App\Repositories\User\AddressRepositoryInterface;

class PersonService
{
    private $repoAddress;
    private $repoUser;

    public function __construct(
        AddressRepositoryInterface $repoAddress,
        UserRepositoryInterface $repoUser,
    ) {
        $this->repoAddress = $repoAddress;
        $this->repoUser = $repoUser;
    }

    // Add your functions here...
}

Scaffold Layers from Models

Instead of generating files one by one, you can scaffold repositories for all models at once:

php artisan layers:scaffold

This command scans the models directory (configured in layers.path.models) and generates an Interface and Eloquent pair for every model found.

Example — given the following models:

app/Models/
├── User.php
├── Company.php
└── Auth/
    └── Token.php

Running layers:scaffold generates:

app/Repositories/
├── UserRepositoryInterface.php
├── UserRepositoryEloquent.php
├── CompanyRepositoryInterface.php
├── CompanyRepositoryEloquent.php
└── Auth/
    ├── TokenRepositoryInterface.php
    └── TokenRepositoryEloquent.php

To also generate a service for each model, use the --with-service flag:

php artisan layers:scaffold --with-service

If a file already exists, it will be skipped automatically — no files are overwritten.

cebpereira/layers 适用场景与选型建议

cebpereira/layers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 cebpereira/layers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 cebpereira/layers 我们能提供哪些服务?
定制开发 / 二次开发

基于 cebpereira/layers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 37
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-14