I have 3 tables :legalpursuit , guarantors, guarantors_legalpursuit. and I have Many To Many Relationships in my project. I save legalpursuit_id in legalpursuit / guarantors_id in guarantors / and both of them in guarantors_legalpursuit.
I am using the laravel 8. how can I show every post's tags ? how can I select data from tag_post table? I use it as follows. but it does not get the data.
it's my Legalpursuit model:
public function guarantorses()
{
//return $this->belongsToMany(RelatedModel, pivot_table_name, foreign_key_of_current_model_in_pivot_table, foreign_key_of_other_model_in_pivot_table);
return $this->belongsToMany(Guarantors::class, 'guarantors_legalpursuit', 'legalpursuit_id', 'guarantors_id');
}
it's my Guarantor model:
public function legalpursuits()
{
//return $this->belongsToMany(RelatedModel, pivot_table_name, foreign_key_of_current_model_in_pivot_table, foreign_key_of_other_model_in_pivot_table);
return $this->belongsToMany(LegalPursuit::class,'guarantors_legalpursuit','guarantors_id', 'legalpursuit_id');
}
and it's my controller :
public function edit(LegalPursuit $legalPursuit, $id)
{
$user = Auth::user();
$data = LegalPursuit::find($id);
$guarantors = $data->guarantorses()->orderBy('name')->get();
$lawyers = $data->lawyers()->orderBy('name')->get();
dd($guarantors);
$filesPursuit = LegalPursuit::find($id)->files;
$getLawyersLeft = DB::table('users')->where('user_type', '2')
->where('active', '1')
->where('deleted', '0')
->take('5')
->get();
return view('pages.legalpursuit.edit', compact('data', 'getLawyersLeft', 'filesPursuit', 'user'));
}