Answer the question
In order to leave comments, you need to log in
How to link two tables in Laravel?
Hello.
I have a table where values from two columns need to be related to values in one column from another table.
As I understand it, the many to many method is suitable, but it was not possible to implement it on my own.
How can this be done in Laravel?
Answer the question
In order to leave comments, you need to log in
You need
hasOne(МодельСвязаннойТоблицы::class, 'название поля по которому связываем в нашей таблице', 'название поля по которому связываем в связываемой таблице')
public function events(){
return $this->hasOne(Events::class, 'city_id', 'id');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question