Loading A relationship collection

Posted 4 months ago by xtremer360

I'm trying to test that a collection of past events are loaded to be shown in the view for a venue. As of right now with the code blocks below regardless if the first line of the show method is commented OR not the test passes. Should this be a concern for me?

/**
* Display the specified venue.
*
* @param  Venue $venue
* @return \Illuminate\Http\Response
*/
public function show(Venue $venue)
{
    // $venue->load('pastEvents');

    return response()->view('venues.show', ['venue' => $venue]);
}
 /** @test */
public function venues_past_events_are_eager_loaded_for_venue_page()
{
    $response = $this->actingAs($this->authorizedUser)
                                     ->get(route('venues.show', $this->venue->id));

    $this->assertTrue($response->data('venue')->relationLoaded('pastEvents'));
}

venue.show

@foreach($venue->pastEvents as $event)
@endforeach

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.