lundi 30 mars 2020

Laravel - Return only multiple relationships with records from controller or model

I'm returing a model with all the related models. My problem is that perhaps some models don't have records so they are returned in my $property variable as empty and I have to evaluate their existence in blade (not done yet) Is there any way in controller or parent model to return only the child relationships which have records? Or any blade directive to evaluate these cases? All relationships are 1:M.

Regards!

Controller Code

class PropertyController extends Controller
{
    public function details($id)
    {
        $property = Property::with('attributes', 'addons', 'distributions', 'images', 'attributes_2', 'services')
                    ->where('prop_id', $id)
                    ->first();
        // dd($property);
        return view('pages.processes.offerdemand.matchs.propertymodal', compact('property'));
    }
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire