Laravel : How to check if relation have rows inside relation? -
this:
//model public function logo(){ $logo = $this->belongsto(media::class, 'image_id'); echo $logo->count(); } //template echo $product->logo;
gives me output 32, there 1 row. if run outside relation :
//model public function logo(){ return $this->belongsto(media::class, 'image_id'); } //template echo $product->logo()->count();
output 1. how check how many rows have relation inside relation ?
try product::with('logo')->first(); // or product::findorfail($id) specific product , based on query, try count($model->relationmethodname)
, see if number looking for.
Comments
Post a Comment