Answer the question
In order to leave comments, you need to log in
To many via laravel eloquent - how to make a tricky request?
Hello.
There are 3 tables - doctors, clients, ClientCourse, as a connection between a client and a certain course in the system.
*client_course*
id
name
doctor_id
client_id
public function clients()
{
return $this->hasManyThrough('App\Client', 'App\ClientCourse');
}
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'clients.client_course_id' in 'on clause' (SQL: select `clients`.*, `client_course`.`doctor_id` as `laravel_through_key` from `clients` inner join `client_course` on `client_course`.`id` = `clients`.`client_course_id` where `client_course`.`doctor_id` = 1)
Answer the question
In order to leave comments, you need to log in
on `client_course`.`id` = `clients`.`client_course_id`
You obviously made a mistake here.
public function clients()
{
return $this->hasManyThrough('App\Client', 'App\ClientCourse');
}
You have a many-to-many relationship, just hasMany(Client::class)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question