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? (30 h 41 min)

You also get:

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

Already a member? Login here

Comments & Discussion

KS
Kacper Stryjewski ✓ Link copied!

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)"}
PK
Povilas Korop ✓ Link copied!

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.

JN
Jemmeli Nejmeddine ✓ Link copied!

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

JN
Jemmeli Nejmeddine ✓ Link copied!

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

PK
Povilas Korop ✓ Link copied!
JN
Jemmeli Nejmeddine ✓ Link copied!

thank you

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.