ahmed-aliraqi/crud-generator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ahmed-aliraqi/crud-generator

Composer 安装命令:

composer require ahmed-aliraqi/crud-generator

包简介

This package is a useful tool to generate simple crud for laravel-modules/scaffolding

README 文档

README

Introduction

This package is a useful tool to generate simple crud for laravel-modules/scaffolding

the files that will be generated is:

  • Lang Files (ar & en)
  • Breadcrumb File
  • View Files
  • Api Resource Files
  • Migration Files
  • Factory File
  • Policy Files
  • Controller Files
  • Model Files
  • Request Files
  • Filter Files
  • Test Files

Installation

composer require ahmed-aliraqi/crud-generator --dev

Configuration

You should add config file using the following command to configure the supported resources.

php artisan vendor:publish --provider="AhmedAliraqi\CrudGenerator\CrudServiceProvider"

Then add the following comment line in the routes/dashboard.php and routes/api.php files:

/*  The routes of generated crud will set here: Don't remove this line  */

And the follwing comment line in the resources/views/layouts/sidebar.blade.php file:

{{-- The sidebar of generated crud will set here: Don't remove this line --}}

Usage

For example if you want to generate a new CRUD named category. make sure it's arabic words was defined in arabicWords of config file and then use the following artisan command:

php artisan make:crud category

Use translatable option if the CRUD is translatable:

php artisan make:crud category --translatable

Use has-media option if the CRUD has media:

php artisan make:crud category --has-media

Also you can use both options together to generate translatable and has media CRUD.

php artisan make:crud category --translatable --has-media

Account Type Cloner

php artisan account:clone customer merchant

This command will clone customer account type to another type named merchant,

Some files should be modified manually like:

  • add constant for the newly generated type in app/Models/User.php
/**
 * The code of merchant type.
 *
 * @var string
 */
const MERCHANT_TYPE = 'merchant';

Then register the type in childTypes array:

/**
 * @var array
 */
protected $childTypes = [
    // other types ...
    self::MERCHANT_TYPE => Merchant::class,
];
  • Add check for type helper in app/Models/Helpers/UserHelper.php:
/**
 * Determine whether the user type is merchant.
 *
 * @return bool
 */
public function isMerchant()
{
    return $this->type == User::MERCHANT_TYPE;
}
  • Add seeders in database/seeders/UserSeeder.php:
Merchant::factory()->count(10)->create();
  • Add translation lang file name to config/lang-generator.php
    'lang' => [
        // ...
        'merchants' => base_path('lang/{lang}/merchants.php'),
        /*  The lang of generated crud will set here: Don't remove this line  */
    ],
  • Update arabic translations in lang file for generated type lang/ar/merchants.php
  • Add type translated key into lang/{lang}/users.php:
'types' => [
    // Other types ...
    'merchant' => 'Merchant',
],
  • Clone view files in dashboard from customer directory to merchant and replace all customer word to merchant
    • Customer => Merchant
    • customers => merchants
    • customer => merchant
  • Add Sidebar link in resources/views/dashboard/accounts/sidebar.blade.php:
[
    'name' => trans('merchants.plural'),
    'url' => route('dashboard.merchants.index'),
    'can' => ['ability' => 'viewAny', 'model' => \App\Models\Merchant::class],
    'active' => request()->routeIs('*merchants*'),
], 
  • Add the routes for the newly generated type in routes/dashboard.php file:
// Merchants Routes.
Route::get('trashed/merchants', 'MerchantController@trashed')->name('merchants.trashed');
Route::get('trashed/merchants/{trashed_merchant}', 'MerchantController@showTrashed')->name('merchants.trashed.show');
Route::post('merchants/{trashed_merchant}/restore', 'MerchantController@restore')->name('merchants.restore');
Route::delete('merchants/{trashed_merchant}/forceDelete', 'MerchantController@forceDelete')->name('merchants.forceDelete');
Route::resource('merchants', 'MerchantController');
  • Add route binding in storage/soft_deletes_route_binding.json:
{
 "trashed_merchant": "App\\Models\\Merchant"
}
  • Add the permision in storage/permissions.json:
[
    "manage.merchants"
]
  • Add actingAsMerchant helper into tests/TestCase.php
  /**
   * Set the currently logged in merchant for the application.
   *
   * @param null $driver
   * @return \App\Models\Merchant
   */
  public function actingAsMerchant($driver = null)
  {
      $merchant = Merchant::factory()->create();

      $this->be($merchant, $driver);

      return $merchant;
  }

ahmed-aliraqi/crud-generator 适用场景与选型建议

ahmed-aliraqi/crud-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.22k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 ahmed-aliraqi/crud-generator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 5.22k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 12
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-04