When you try
$garments = Garment::with('properties')->where('is_active', true)->get();
What do you get?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have the following:
Garment.php:
public function properties(){
return $this->belongsToMany('App\Property');
}
Property.php:
public function garments(){
return $this->belongsToMany('App\Garment');
}
Following laravel convention for table names : Garments, Properties. Fks: garment_id, property_id . They have a many-to-many relationship.
I'm Trying to get collection of garments with the properties.
$g= garment::where('is_active',1)->with(['properties'])->select('garments.id','garments.name as name','garments.display','garments.is_new')->get();
The query returns a collection of objects but some objects don't return their properties. They all should have properties.
I can't figure out why there are a handful of garments that don't have their properties attached.
Note: I can do the following and it works as intended for all objects, so I know the relation exists.
garment::where('id',7)->properties();
SInce I was using uuid's for the tables, the model required:
protected $keyType = 'string';
It was converting the uuid to int somewhere.
Please or to participate in this conversation.