-1
I am making a system for a school in the automotive sector that offers courses, this system the user will be able to register the courses and view them, in general, will be a panel for him to control what he puts/ remove from the site.
Throughout the development of the system there were some doubts in the Laravel Migrations, I tried to find in other sources, but I did not get any common result to mine, amazingly, most start using the command php artisan make:model nome_da_tabela -m
(-m to generate migrate), but I ended up doing the opposite, I started by migrates to then generate all the tables at once.
I have 3 Migrations/tables, but I don’t know what the final result of the associative table will look like, I mean regarding the types of data and the references I should put in the table course_category
create_course_table
create_course_category_table
create_category_course_table
On the table course_category
how I will insert and identify the table id course
and category_course
?
I thought I’d put as FK the two of the table category_course
, but I do not know if it is feasible knowing that it is a table of N:N
Example:
$table->foreign('id_course')->references('id')->on('course')
$table->foreign('id_category_course')->references('id')->on('category_course')
However this form quoted above may be quite wrong working with Laravel. I do not know, I have no way to state.
This question may be duplicated in Migrations in Laravel 5.8 but it was not answered...
You need to know how to create a Migration?
– novic
Actually my question is whether in Migration would the associative table or not, from what I saw, will not... You use the pivot command to retrieve the data from the intermediate table, I just didn’t understand how to insert it.
– user152996
But there needs to be a table and consequently a migrate from these tables, summarizing are 3 Migration
– novic
But from what I understood (correct me if I’m wrong) it will be 2 tables... Course and category_course that will exist in my models folder, and if I want to get the information of the 2 tables I must use the pivot command. If not that, how will I do when mounting my course_category migrate? will have migrate id, and the keys referenced, should I use some Laravel 5 command to reference them? Type $table->Foreign('id_course')->References('id')->('id_course');?
– user152996
There will be three Migration, one course, the other category and the other category? that’s what you need?
– novic
Oh yes! I get it. But it would be right if I put.
$table->BigIncrements('id');
$table->foreign('id_course')->references('id')->on('course');
$table->foreign('id_category_course')->references('id')->on('category_course');
?– user152996
You need to create 3 migrate one for each table and in Laravel are created 2 Models that relate many to many... !!! understood?
– novic
Already has explanation for the creation of the models here
– novic
Okay! Sorry to ignore, you’ve helped a lot.
– user152996