To link POST, PUT, DELETE routes and functions to handle, we should use the post, put
and delete methods of Route class in the api.php file which is located in the “routes” folder.
Figure 5 represents code to define route name api.adm.tasniflagich.mf.uz/category and
handlers as store, update and delete in CategoryController class. As we can see there is the same
route name but different methods and different handlers.
Figure 5. define post, put and delete methods
3.3.2 apiResource method
Sometimes we need to create routes to manipulate models. The model must be able to
Create, Read, Update, and Delete resources. The Route class has a special method for this case
named “apiResource”. The method apiResource link predefined Controller methods as index,
show, store, update and delete with routes and related request methods.
Figure 6. CRUD in 1 row via apiResource
In figure 6 with 1 method we created 5 routes:
1. GET /category - index
of all available categories
2. GET /category/{id}
- data of category by id
3. POST /category
- route to create category
4. PUT /category/{id} -
route to edit category by id
5. DELETE /category/{id} - route
to delete category by id
TTPU
15
2022