问题
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