Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,153,496 members, 7,819,811 topics. Date: Tuesday, 07 May 2024 at 12:19 AM |
Nairaland Forum / Science/Technology / Programming / Laravel Relationship Problem (332 Views)
Do You Need A Backend Developer (PHP Or Laravel) / Full Time Laravel or Symfony Framework Php/js Developers Are Urgently Needed / Consuming Laravel Api In Android (2) (3) (4)
Laravel Relationship Problem by efelico: 2:22am On Jun 15, 2022 |
Please someone should help me with the laravel relationship problem. Here is the problem description https://stackoverflow.com/questions/72624835/select-other-data-in-another-table-using-eloquent |
Re: Laravel Relationship Problem by tollyboy5(m): 8:19am On Jun 15, 2022 |
Your question has been answered from that link already |
Re: Laravel Relationship Problem by Karleb(m): 9:02am On Jun 15, 2022 |
You can watch a short video on how many to many relationship works. Your question already has a detailed answer. |
Re: Laravel Relationship Problem by efelico: 3:16pm On Jun 15, 2022 |
Re: Laravel Relationship Problem by yankeecoder: 6:42pm On Jun 16, 2022 |
You'll need 3 tables to form a link between many judges and many cases and then your witness table making it a total of 4 tables. 1. cases table: id, title 2. judges table: id, name 3. judge_case table: case_id, judge_id 4. witness table: id, case_id below is the eloquent snippet for the Case class: class Case extends Model { public function judges() { return $this->belongsToMany(Judge::class); } public function witnesses() { return $this->hasMany(Witness::class); } } this one below is the eloquent snippet for the judge class class Judge extends Model { public function cases() { return $this->belongsToMany(Case::class); } } to pull up all judges with all their cases, all you need is $judges = Judge::with('cases')->get(); to pull up all cases with their judges and witness, all you need is $cases = Case::with(['judges', 'witnesess'])->get(); |
(1) (Reply)
Best Tools To Create Visualizations / Urgent Attention / Download Paybeta Mobile App On Google Playstore
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9 |