简体   繁体   中英

Relationship il Laravel 8 using three tables

Can some home help me to make this request using laravel Relationship? SELECT * FROM `recoltes`, `plantations`, `users` WHERE recoltes.plantation_id = plantations.id AND plantations.user_id = users.id;

Yes i found a way

public function recoltes ()
{
    return $this->hasManyThrough(Recolte::class, Plantation::class);
}

Note that when i start with ```Plantation::class``` it does not work.
For that to work, You should specify how fields are related between tables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM