What is the use of laravel's RESTful resource controller?
滿天的星座2017-05-16 16:46:49
0
3
489
Can’t understand what RESTful means in this section? Why are there so many routes using this setting? What are the benefits of this? What should I do if I don’t use the created ones? Route::resource('photo', 'PhotoController');
The resource controller can specify the resource model It is to add some operations of adding, deleting, checking and modifying by default to beautify the code. php artisan make:controller PhotoController --resource --model=Photo It is boring to eat, it is a pity to leave it, it is really of no use. Familiar with laravel's specifications, you should learn the same coding style as him .
Visiting a website represents an interactive process between the client and the server. In this process, changes in data and status are bound to be involved. Internet communication protocol HTTP protocol is a stateless protocol. This means that all state is saved on the server side. Therefore, if the client wants to operate the server, it must use some means to cause "State Transfer" to occur on the server side. This transformation is based on the presentation layer, so it is "presentation layer state transformation". The method used by the client can only be the HTTP protocol. Specifically, there are four verbs indicating operation methods in the HTTP protocol: GET, POST, PUT, and DELETE. They correspond to four basic operations: GET is used to obtain resources, POST is used to create new resources (can also be used to update resources), PUT is used to update resources, and DELETE is used to delete resources. RESTful architecture has some typical design misunderstandings. One of the most common design mistakes is that the URI contains verbs. Because "resource" represents an entity, it should be a noun, URI should not have verbs, and verbs should be placed in the HTTP protocol. For example, a certain URI is /posts/show/1, where show is a verb. This URI is designed incorrectly. The correct writing method should be /posts/1, and then use the GET method to represent show. For more details, please refer to: RESTful-Wikipedia
Detailed instructions in the document
The resource controller can specify the resource model
It is to add some operations of adding, deleting, checking and modifying by default to beautify the code.
php artisan make:controller PhotoController --resource --model=Photo
It is boring to eat, it is a pity to leave it, it is really of no use. Familiar with laravel's specifications, you should learn the same coding style as him .
Visiting a website represents an interactive process between the client and the server. In this process, changes in data and status are bound to be involved.
Internet communication protocol HTTP protocol is a stateless protocol. This means that all state is saved on the server side. Therefore, if the client wants to operate the server, it must use some means to cause "State Transfer" to occur on the server side. This transformation is based on the presentation layer, so it is "presentation layer state transformation".
The method used by the client can only be the HTTP protocol. Specifically, there are four verbs indicating operation methods in the HTTP protocol: GET, POST, PUT, and DELETE. They correspond to four basic operations: GET is used to obtain resources, POST is used to create new resources (can also be used to update resources), PUT is used to update resources, and DELETE is used to delete resources.
RESTful architecture has some typical design misunderstandings.
One of the most common design mistakes is that the URI contains verbs. Because "resource" represents an entity, it should be a noun, URI should not have verbs, and verbs should be placed in the HTTP protocol.
For example, a certain URI is /posts/show/1, where show is a verb. This URI is designed incorrectly. The correct writing method should be /posts/1, and then use the GET method to represent show.
For more details, please refer to: RESTful-Wikipedia