Wednesday, April 12, 2017

How to use "with" in laravel?

I use this package : https://github.com/jenssegers/laravel-mongodb

My laravel eloquent is like this :

$query = Product::where('store_id', $id)       
                ->with('store')
                ->get();

My product model is like this :

public function store()
{
    return $this->belongsTo(Store::class, 'store_id', '_id');
}

When I execute dd($query), the result is like this :

enter image description here

Whereas I see in the database, the data exist

I try change to be like this :

return $this->belongsTo(Store::class, 'store_id', 'id');

It's the same

How can I solve this problem?



via samuel toh

Advertisement