S
S
Sergey Chazov2019-04-06 23:42:05
Laravel
Sergey Chazov, 2019-04-06 23:42:05

How to establish two one-to-many relationships in Laravel?

There is a table Dot_tasks
In it columns responsible_id and autor_id
Each of the columns indicates the user id from the table Users
Users and Dot_tasks relate to each other as one to many. How to establish a connection in models?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ARX2, 2019-04-07
@chazovs

Controller:

public function autors(){ // Зависит от того как у тебя модели называются
$users = User::with('autor')->get();
dd($users); //Заходишь в realtination и видишь связку
}

Model:
public function autor{
return $this->hasMany('App\Dot_tasks', 'autor_id', 'id'); //Зависит как у тебя модель называется
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question