Skip to main content

Finishing CRUD: Update, Delete and Resource Controller

Premium
5:00

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Kacper Stryjewski avatar

Hello, What if we have a relation in the products table to some category? Should we add in our migration some onDelete, onUpdate events? I got an error like this:

{"message": "SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`laravel_api`.`products`, CONSTRAINT `products_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`)) (Connection: mysql, SQL: delete from `categories` where `id` = 2)"}
Povilas Korop avatar

It depends on what you want to do on that update/delete events. One of the ways is to have ->cascadeOnDelete() at the end, so it would delete the related records.

Jemmeli Nejmeddine avatar

those constant from symphony i check the documentation in laravel but they are not mentionned there .

Jemmeli Nejmeddine avatar

I have a question one of you recommendations is not to pass " $request->all() " in order to create because is not unsafe ?

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.