Support the ongoing development of →
Database Eloquent
Last updated 1 year ago.

You are fetching the same data twice by using the find() in both lines. You could just use the query you have for $campaignStatus. That query would return a Collection object with both the variables you are passing to your view.

Or try using the one query:

$campaign = Campaign::find($id)->campaignStatus;
Last updated 1 year ago.


 $campaign = Campaign::find($id);

will populate the $campaign with model data, Since id is already set, now you can get the comaign status like ( another find call was not needed ):

$status = $campaign->campaignStatus;
$status = $campaign->campaignStatus()->first();

this will return the related stutus for the campaign.

Last updated 1 year ago.

Sign in to participate in this thread!


Your banner here too?

jasondavis jasondavis Joined 19 Feb 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.