Answer the question
In order to leave comments, you need to log in
What does this migration entry mean?
$table->increments('id');
$table->string('owner');
$table->string('image_url');
$table->timestamps();
$table->foreign('owner')
->references('id')
->on('users');
What exactly does it mean:
$table->foreign('owner')
->references('id')
->on('users');
Answer the question
In order to leave comments, you need to log in
The difference is that with a foreign key you will not be able to insert data into the table that is not in the link table in the column with the foreign key, and you will also not be able to delete this entry if this foreign key is used in the link table.
If you specify this in the model, then it will be the same as without the foreign key, but as I said above, you will not be immune from deletions and null insertions. And also for foreign, you can also add a strategy, for example
Which would mean that when a user is deleted, the records from this table that contain the foreign key referring to the user will be deleted.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question