Laravel - Create automated CRUD?

馋奶兔 提交于 2020-01-22 04:07:05

问题


Is Artisan got a tool for create the code of a CRUD automated in Laravel? I search information about it but all the options are with an external tool outside of Artisan.


回答1:


create the code of a CRUD

 No!

But if you want the CRUD methods copied from a properly defined stub use

php artisan make:controller EntityController -r

where the -r flag means a resourceful controller for the model Entity with create, show, index, store, update, edit, and delete methods

The methods uses the proper parameters and apply convenient Dependency Injection and are named according to

Route::resource('Entity', 'EntityController');

However you must write your own implementation




回答2:


php artisan make:model Entity -mrc

It create a model & migration file & a resource Controller name EntityController.

To create only a resource controller,

php artisan make:controller EntityController --resource

This command will generate a controller at app/Http/Controllers/EntityController.php

In here you have 7 functions

1.index(to show all data)

2.create(to get the blade file creation)

3.store(to store data into database)

4.show(to show specific data)

5.edit(to get the edit blade file )

6.update(to update that specific data into database)

7.destroy(to delete data)

Next, you may register a resourceful route to the controller:
Route::resource('entities', 'EntityController');


来源:https://stackoverflow.com/questions/58050299/laravel-create-automated-crud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!