{{$zapisevent->eventsave->name}}
Ale jak korzystam z tego to mam error, że niby name nie istnieje:
Property [name] does not exist on this collection instance. (View: /home/mariusz/Pulpit/www/szpital/resources/views/profil/profil.blade.php)
Więc wyświetlam relacje w taki sposób:
@foreach($zapisevents as $zapisevent) <table class="table"> <th>{{$zapisevent->eventsave->name}}</th> </table> @endforeach
Controller do wyświetlania relacji:
public function index() { $userid = Auth::user(); $zapisevents = User::with('eventsave')->where('id',(Auth::user()->id))->get(); return view('profil.profil', ['userid' => $userid], ['zapisevents' => $zapisevents]); }
Model User:
public function eventsave() { return $this->belongsToMany(HomeModel::class,'save_events','users_id','events_id')->withTimestamps(); }
Model HomeModel <- odpowiedzialny za eventy:
public function usersave() { return $this->belongsToMany(User::class,'save_events','events_id','users_id'); }