[Laravel5.1-0.0.4] easy Restful routing and control
My book: http://www.jianshu.com/users/85c8826ce087/latest_articles
The following uses the CURD operation in the article as an example. This article only covers the basic routing and controller> methods. the specific implementation will be further explained later.
1. create a route
2. Controller
-
Create a controller through the terminal
Php artisan make: controller ArticleController
-
Get the controller app/Http/Controllers/ArticleController
-
If you want to create a folder under app/Http/Controllers and create a controller class in the folder, you can run the following command:
Php aritsan make: controller Article/ArticleController
-
Controller class example:
3. (routing ---> controller) Restful reference link example table:
| Request method |
Route address |
Corresponding controller method |
Corresponding route name |
Current role |
| GET |
/Article |
Index () |
Route ('article. index ') |
Show article list |
| GET |
/Article/ |
Create () |
Route ('article. create ') |
Document creation page |
| POST |
/Article |
Store (Request $ request) |
Route ('article. store ') |
Document Storage Operations |
| GET |
/Article/{id} |
Show ($ id) |
Route ('article. index ') |
Show article details |
| GET |
/Article/{id}/edit |
Edit ($ id) |
Route ('article. edit ') |
Article editing page |
| PUT/PATCH |
/Article/{id }/ |
Update (Request $ request, $ id) |
Route ('article. Update ') |
Document update operations |
| DELETE |
/Article/{id} |
Destroy ($ id) |
Route ('article. destroy ') |
Delete an article |
Note:
If the form is to store an article, action = "route ('article. store')" corresponds to the URL
When accessing localhost: 8000/article, the URL corresponding to route ('article. index') is accessed.