I
I
Iskander Nerusev2016-06-18 03:40:29
Laravel
Iskander Nerusev, 2016-06-18 03:40:29

How to properly create relationships between models and implement a function?

Information system analysis of art and those... The
question is this:
There is a user model, books, and reviews.
It is necessary to correctly register the function of creating a review in the ReviewController ( app/Http/Controllers/ ) so that it is automatically linked to the user who created the review and to the book for which the review was written.
Perhaps the relationships between the models are incorrectly specified.
The database has all the required columns.
There are some crooked attempts to implement this function, you will see all this in the controller itself.
At the moment this error is thrown:

Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`bookshelf`.`reviews`, CONSTRAINT `book_review_book_id_foreign` FOREIGN KEY (`book_id`) REFERENCES `books` (`id`) ON DELETE CASCADE) (SQL: insert into `reviews` (`body`, `user_id`, `updated_at`, `created_at`) values (SOME TEXT SOME TEXT SOME TEXT SOME TEXT , 1, 2016-06-18 03:37:36, 2016-06-18 03:37:36)

That is, book_id is not transmitted when requested.
Review creation form: resources/views/books/reviews/create.blade.php

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D', 2016-06-18
@4ksi

That is, book_id is not transmitted when requested

It shouldn't, because it doesn't appear anywhere.
Pass it manually by sending it along with the `body` in the request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question