我使用这个包:https://github.com/jenssegers/laravel-mongodb
我的laravel雄辩是这样的:
$query = Product::where('store_id', $id)
->with('store')
->get();
我的产品型号是这样的:
public function store()
{
return $this->belongsTo(Store::class, 'store_id', '_id');
}
执行dd($query)
时,结果如下:
我在数据库中看到数据存在
我尝试改变这样:
return $this->belongsTo(Store::class, 'store_id', 'id');
它是相同的
我该如何解决这个问题?
答案 0 :(得分:1)
我认为您可以在此之后解决您的问题:
$query = Product::with('store')->where('store_id', $id)
->get();
在模特中:
public function store()
{
return $this->belongsTo('App\Store','store_id', '_id');
}
并运行此命令:' composer dump-autoload'在命令提示符下。
感谢.....
答案 1 :(得分:0)
尝试
public function store()
{
return $this->belongsTo(Store::class, null, 'store_id', '_id');
}
同时添加
protected $primaryKey = 'your_primary_key';
到你的模特。
希望这会有所帮助。 :)