B
B
Bobur Bakhritdinov2017-07-28 18:58:14
Laravel
Bobur Bakhritdinov, 2017-07-28 18:58:14

Laravel 5 model bundle?

Good afternoon.
Framework: Laravel 5.4
Help me understand, the problem is with the model linkage.
There is a model Files and Movies
in the database there are tables files and movies the
table files store files with movies_id:
b6567b7f88434cc798812db3647c0bc4.png
There is a table movies
8d6d603f3c6944b7b5c17f2498120e6c.png
As shown in the screenshot, there can be several records in the files table with the same movies_id. How to connect them correctly?
Error while adding entry:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'movies_id' cannot be null

Thanks in advance)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
PashaNedved, 2017-07-29
@bakhritdinov_b

Your Movie model is empty. First get the Movie model, then save the related records.

$movie = Movie::find(121);
...
$movie->files()->save($file);

R
Roman Frank, 2017-07-28
@Akellacom

laravel.su/docs/5.0/eloquent
https://laravel.com/docs/5.4/eloquent-relationship...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question