sentgine/crudwizard 问题修复 & 功能扩展

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

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

sentgine/crudwizard

Composer 安装命令:

composer require sentgine/crudwizard

包简介

A simple but powerful Laravel package for effortless CRUD operations.

README 文档

README

License Latest Stable Version Total Downloads

Crudwizard is a powerful Laravel package designed to simplify the process of generating CRUD (Create, Read, Update, Delete) functionality for your Laravel applications. With Crudwizard, you can effortlessly create and manage your database tables, models, controllers, views, and routes with just a few simple commands.

Features

  • Efficient CRUD Generation: Crudwizard provides a streamlined approach to generating CRUD operations, allowing you to create database migrations, models, controllers, views, test, factory, and routes in a matter of seconds.
  • Customizable Templates: The package offers a range of customizable view, enabling you to tailor the generated code to match your project's specific requirements.

Requirements

  • Laravel 10.x or higher.
  • PHP 8.0 or higher.
  • Use Tailwind CSS to make your life easier.

Installation

(1) You can install the package via Composer by running the following command:

composer require --dev sentgine/crudwizard

(2) You must publish the config and view files for better control.

php artisan vendor:publish --tag="crudwizard"

(3) Then, at the root of your laravel project, type the command below. It will ask you the name of the controller and the form fields.

php artisan crudwizard:generate

or

php artisan crudwizard:generate --resource="post"

Sometimes you may want to overwrite the existing resource files. Crudwizard does not allow you to do that by default, as it will skip overwriting your files. You can can just add the --force option to your command.

php artisan crudwizard:generate --resource="post" --force

(4) You can also specify a prefix. It will then create the controller under the Dev/Admin and the views under the folder dev/admin.

php artisan crudwizard:generate --resource="post" --prefix="dev/admin"

(5) If you make a mistake, you can just delete the resource files. Note that this will not delete the migration files. You'll have to manually delete it.

php artisan crudwizard:delete --resource="post"

or

php artisan crudwizard:delete --resource="post" --prefix="dev/admin"

(6) To get you started quickly, I would advise you to copy and paste the entire Tailwind CSS @layer component directive below. You can customize this later.

@layer components {
    /* Common */
    .crudwizard-resource-container {
      @apply w-full p-10 grid grid-cols-1 gap-4;
    }
    .crudwizard-top-container {
        @apply grid grid-cols-1 gap-5 md:flex justify-between whitespace-nowrap;
    }
    .crudwizard-top-sub-container {
        @apply grid grid-cols-1 gap-3 md:flex;
    }
    .crudwizard-resource-title {
        @apply font-semibold text-2xl;
    }    

    /* Table */
    .crudwizard-table-container {
        @apply rounded-md border grid grid-cols-1 gap-3;
    }
    .crudwizard-table {
        @apply text-left w-full shadow-lg;
    }
    .crudwizard-thead {
        @apply bg-gray-700 text-white;
    }
    .crudwizard-body {
        @apply text-left;
    }
    .crudwizard-th {
        @apply p-2;
    }
    .crudwizard-th-action {
        @apply w-[200px];
    }
    .crudwizard-tr {
        @apply border-b;
    }
    .crudwizard-td {
        @apply px-2;
    }
    .crudwizard-td-action {
        @apply border p-2 px-3 grid grid-cols-1 gap-3  md:w-auto md:flex;
    }
    .crudwizard-pagination-container {
        @apply mt-2;
    }
    .crudwizard-resource-no-results {
        @apply text-left;
    }

    /* Form */
    .crudwizard-invalid-input {
        @apply border-2 border-red-600;
    }
    .crudwizard-invalid {
        @apply text-red-600 text-sm;
    }
    .crudwizard-form-container {
        @apply border p-5 w-full sm:w-8/12 md:w-7/12 lg:w-5/12;
    }
    .crudwizard-form {
        @apply grid grid-cols-1 gap-4;
    }
    .crudwizard-form-fieldset {
        @apply grid grid-cols-1 gap-2;
    }
    .crudwizard-form-text-input {
        @apply border py-1 px-2;
    }

    /* Buttons */
    .crudwizard-button {
        @apply text-white px-2 py-2 rounded text-sm uppercase flex justify-center items-center gap-2;
    }
    .crudwizard-back-button {
        @apply crudwizard-button bg-gray-100 hover:bg-gray-200 text-gray-800;
    }
    .crudwizard-save-button {
        @apply crudwizard-button bg-green-800 hover:bg-green-900;
    }
    .crudwizard-add-new-button {
        @apply crudwizard-button bg-blue-800 hover:bg-blue-900;
    }
    .crudwizard-show-button {
        @apply crudwizard-button bg-purple-800 hover:bg-purple-900 text-xs;
    } 
    .crudwizard-edit-button {
        @apply crudwizard-button bg-yellow-800 hover:bg-yellow-900 text-xs;
    }
    .crudwizard-delete-button {
        @apply crudwizard-button bg-red-800 hover:bg-red-900 text-xs;
    }
    .crudwizard-modal-delete-yes-button {
        @apply crudwizard-delete-button mt-5 min-w-[100px];
    }
    .crudwizard-modal-delete-cancel-button {
        @apply crudwizard-button bg-gray-500 mt-5 min-w-[100px];
    }
    
    /* Modal */
    .crudwizard-modal-container {
        @apply fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 z-50;
    }
    .crudwizard-modal-subcontainer {
        @apply bg-white rounded-lg p-6 shadow-xl grid grid-cols-1 gap-2;
    }
    .crudwizard-heading {
        @apply text-lg font-bold;
    }
    .crudwizard-button-container {
        @apply flex justify-between;
    }
  }

(7) Make sure you run your Laravel local server.

php artisan serve

(8) Open another terminal, and run the command below to compile and build your frontend asssets.

npm run dev

(9) You can explore other commands as well.

php artisan crudwizard --help

Testing

By default, generating the CRUD will create a test file. There are two things you need to do to be able to test this.

(1) Add this code below to your Laravel app's config/database.php file under the connections key.

'testing' => [
    'driver' => 'mysql',
    'host' => env('DB_TEST_HOST', '127.0.0.1'),
    'port' => env('DB_TEST_PORT', '3306'),
    'database' => env('DB_TEST_DATABASE', 'test_database'),
    'username' => env('DB_TEST_USERNAME', 'root'),
    'password' => env('DB_TEST_PASSWORD', ''),
    'unix_socket' => env('DB_SOCKET', ''),
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'prefix_indexes' => true,
    'strict' => true,
    'engine' => null,
    'options' => extension_loaded('pdo_mysql') ? array_filter([
        PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
    ]) : [],
],

(2) Under the root directory of your Laravel app, you will see a phpunit.xml file. Add this code below inside the "php" tag.

<env name="DB_CONNECTION" value="testing"/>
<env name="DB_TEST_HOST" value="127.0.0.1"/>
<env name="DB_TEST_PORT" value="3306"/>
<env name="DB_TEST_DATABASE" value="test_database"/>
<env name="DB_TEST_USERNAME" value="root"/>
<env name="DB_TEST_PASSWORD" value=""/>

This will allow you to use a new database for your test. It is generally good practice not to use the configuration for your live database. Instead, use a separate database for testing.

(3) And add this to your .env file under the root of your Laravel app.

DB_TEST_HOST=127.0.0.1
DB_TEST_PORT=3306
DB_TEST_DATABASE=core_test_database
DB_TEST_USERNAME=root
DB_TEST_PASSWORD=

Changelog

Please see the CHANGELOG file for details on what has changed.

Security

If you discover any security-related issues, please email sentgine@gmail.com instead of using the issue tracker.

Credits

Crudwizard is built and maintained by Adrian Alconera. Visit my YOUTUBE channel!

License

The MIT License (MIT). Please see the LICENSE file for more information.

sentgine/crudwizard 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-14