Update a Genre

Learn how to implement a controller that updates the existing data in a database.

Setting up the controller

Let’s imagine an administrator misspells a genre’s name or just wants to change it. They would need to modify it, so we need to make an endpoint to allow them to do this. This endpoint searches for the genre they want to edit, lets them pass the new value, and then sends the modified value to the database.

We’re going to create a simple controller that asks for the genre_id as a parameter. It includes an authorization check to ensure that the user attempting to access it belongs to the ADMIN type. Following that, the function will search the database for the genre and update the relevant field.

Get hands-on with 1400+ tech skills courses.