Laravel Restful Actions
We often use controllers for list some products, add product, update product or Delete product. Now we are dig into for make easy understand the flow. For all this actions you can categorize the 7 Restful actions.
php artisan help make:controller
Controller options
Let use one of the options to make all 7 Restful actions. Create new controller for Products
php artisan make:controller PostsController -r -m Posts
In this statement you used -r -> resources and -m -> model. It will create PostsController and Posts Model files
Posts.php
Here you covered all Restful actions for Product, to add, show, edit or delete. If you are not run the command you can write all these 7 Restful actions manually.
However, you have to mention all this actions at routes and correspond actions with HTTP verbs like GET, POST, PUT and DELETE.
Ex:
GET Products (List of products)
GET Products/:id (Single Product)
PUT Products/:id (For product update)
POST Products (Create a Product)
Delete Products/:id (Delete a product)
Comments
Post a Comment
Thank you :)