Phpartisan common method 1. generate a controller
php artisan make:controller PhotoController
2. generate a controller using RESTFUL
php artisan make:controller PhotoController --resource
Route::resource('photo', 'PhotoController');
Why do we use the resource parameter? because we design the add, delete, modify, and query operations in the background, and these operations can be directly generated using the -- resource method, Route :: resource actually generates a fast route, so the Get, post, and delete operations that we need to write are directly generated in one click using the restful method. Note that index is a list, store is new, show is Details, update is modification, and destory is delete.
3. generate a model
Php artisan make: model User-m
Generate a user model and generate a database creation file
4. PHP Data table maintenance (migration)
New migration:
php artisan make:migration create_users_table
The new migration is located in the database/migrations directory, and each migration file name contains a timestamp, allowing Laravel to determine its order.
The -- table and -- create options can be used to specify the table name and whether to create a new data table for the migration. These options only need to be placed after the preceding migration command and specify the table name:
php artisan make:migration add_votes_to_users_table --table=usersphp artisan make:migration create_users_table --create=users
Run migration:
php artisan migrate
5. fill in data
New fill:
php artisan make:seeder UserTableSeeder
Run the filler:
Php artisan db: seed
Php artisan db: seed -- class = UserTableSeeder
You can also use the migrate: refresh command to fill the database. this command can also be rolled back and re-run the migration, which is useful when you need to completely recreate the database:
Php artisan migrate: refresh -- seed