raphaelvilela / crud-rails
Rails 创建超级快速的 CRUD。
1.0.3
2018-03-29 03:50 UTC
Requires
- guzzlehttp/guzzle: ~6.0
- intervention/image: 2.4.0
- laravel/framework: 5.5.*
This package is not auto-updated.
Last update: 2024-10-02 05:08:25 UTC
README
##安装要安装此包,需要执行以下命令
composer require raphaelvilela/crud-rails
php artisan vendor:publish
需要发布包的文件 laravel-pagination 和 raphaelvilela/crud-rails。
##使用要创建一个 CRUD,需要遵循以下步骤
###步骤 01 - 创建模型我们建议您从以下命令创建模型,因为这样可以同时创建 migration 和 controller
php artisan make:model NomeDoModelo -mc
根据您的兴趣字段合理修改 migration,然后在您的数据库中执行 migration。
###步骤 02 - 配置模型向您的模型添加以下变量,以便它能够验证所进行的请求。
protected $guarded = [];
public $rules = [
'field_name_01' => 'required',
'field_name_02' => 'required',
'field_name_03' => 'required',
'field_name_04' => 'required',
'field_name_05' => 'required'
];
###步骤 04 - 配置控制器应该修改创建的控制器,使其扩展 ModelController。它还应该告知此控制器引用的是哪个模型。
class NomeDoModelController extends ProductSiteModelController
{
public function __construct()
{
parent::__construct(NomeDoModel::class);
}
###步骤 03 - 构建CRUD视图对于每个 CRUD,都需要创建一个包含两个视图的文件夹:第一个列出记录,第二个创建一个用于注册和修改记录的表单。
nome_do_model/index.blade.php
@extends('crud-rails::forms.list')
@section('list-table')
{{$paginate_models->links()}}
<table class="table table-striped">
<thead>
<th>Name</th>
<th>Ações</th>
</thead>
@foreach($paginate_models as $model)
<tr>
<td>{{$model->name}}</td>
<td>
<a class="btn btn-success btn-sm" href="{{route($model_code . '.edit', ['id' => $model->id])}}">
<i class="fa fa-edit"></i> <span class="hidden-xs">Editar</span>
</a>
<form class="d-inline-block"
method="post"
action="{{route($model_code . '.destroy',['id'=>$model->id])}}">
<input type="hidden" name="_method" value="DELETE"/>
{{ csrf_field() }}
<button type="submit" class="btn btn-danger btn-sm">
<i class="fas fa-times"></i>
</button>
</form>
</td>
</tr>
@endforeach
</table>
{{$paginate_models->links()}}
@endsection
nome_do_model/index.blade.php
@extends('crud-rails::forms.form')
@section('fields')
@include("crud-rails::forms.components.inputText", ['name' => 'name'])
@include("crud-rails::forms.components.submit", ['name' => 'save'])
@endsection
###步骤 04 - 添加路由只需在 routes/web.php 文件中添加以下路由,您就拥有了一个完整的 CRUD。
Route::resource('nome_do_model', 'NomeDoModelController');