ottiem / cruddy
一个功能强大但简单的 Laravel CRUD 构建工具。
dev-main
2022-12-05 22:56 UTC
Requires
- php: >=7.0
- illuminate/console: >=8.0
- illuminate/database: >=8.0
- illuminate/routing: >=8.0
- illuminate/support: >=8.0
- orchestra/testbench: >=6.0.0
- symfony/console: >=5.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-06 02:48:14 UTC
README
为 Laravel 提供简单的 CRUD 创建包。
安装步骤
- composer install ottiem/cruddy
- php artisan vendor:publish
- 在新建的 config/cruddy.php 文件中调整任何设置
- 将 cruddy 连接添加到所有创建您想要转换为基本 CRUD 资源表的迁移中:
Schema::connection('cruddy')
供应商包文件
当您运行 php artisan vendor:publish
时,它将在 config/cruddy.php 中为您创建一个配置文件。这是您设置所有 CRUD 设置和选项的地方。例如,config/cruddy.php 中的 needs_ui
变量控制是否创建前端视图文件。如果您正在创建一个不需要前端 API,则应将此值设置为 false,以便不创建视图文件。
数据库连接
在运行迁移之前正确设置数据库连接,您的 .env 文件中的 APP_ENV
变量不能设置为 testing
或 local
。
// Within config/cruddy.php, we can control the creation of the frontend view files like so:
'needs_ui' => false,
示例
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFooTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection('cruddy')->create('foos', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('bar');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('foos');
}
}
如果这些文件尚不存在,则将根据上述示例创建它们。如果文件已存在,则不会覆盖。
- app/Http/Controllers/FooController.php
- app/Models/Foo.php
- app/Http/Requests/StoreFoo.php
- app/Http/Requests/UpdateFoo.php
- resources/views/foo/create.blade.php
- resources/views/foo/edit.blade.php
- resources/views/foo/index.blade.php
- resources/views/foo/show.blade.php
这将添加到上述示例的 routes/web.php 文件中
// Foo Resource
Route::resource('foos', 'App\Http\Controllers\FooController');