Phpartisan common method-php Tutorial

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.