So I have 2 tables.
DirtyEvent model and Event model.
I am retrieving DirtyEvent with Event which works fine
In blade I have:
@if (\Request::is('profile/event'))
@foreach ($events as $event)
@if (empty( $event->image ))
<div class="card-header">
<span class="card-title"><a href=""> </a></span>
</div>
@else
<div class="card-image">
<img class="img-responsive" src=""></img>
<span class="card-title"><a href=""> </a></span>
</div>
@endif
<div class="card-content">
<p><strong>Starts: </strong>@php echo ($startdate) @endphp - </p>
<br>
@if ($startdate != $enddate)
<p><strong>Ends: </strong>@php echo ($enddate) @endphp - </p>
<br>
@endif
<p><strong>Description:</strong></p>
<br>
<p></p>
</div>
<div class="card-action">
<a href=""><i class="fa fa-pencil-square-o fa-2x" aria-hidden="true"></i></a>
<form method="POST" action=>
<button type="submit" class="delete" style="border:none;"><i class="fa fa-trash-o fa-2x" aria-hidden="true"></i></button>
</form>
</div>
@foreach ($events->publicevents as $eventss)
@endforeach
@endforeach
However dd($events) gives me:
DirtyEvent Collection -> relations -> publicevents -> Event collection
but it is saying that publicevents do not exist in current collection.
ControlleR:
public function index()
{
$id = Auth::id();
$events = DirtyEvent::where('user_id', $id)
->with('publicevents')
->get();
return view('events.viewEvent', compact('events'));
}
model:
public function publicevents()
{
return $this->hasMany('App\Event', 'event_id');
}
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2vHvBuC
via IFTTT
Aucun commentaire:
Enregistrer un commentaire