所以,我刚刚尝试使用多态性在laravel中建立关系。
使用dd()时出现数据,但是删除“ dd()”后不出现数据
public function submission()
{
return $this->morphTo('data');
}
$storage = ItemStorage::where('id', $barang_id)->first();
$barang = $storage->submission;
dd($barang);
Submission {#2218 ▼
#table: "barang"
#fillable: array:23 [▶]
#dates: array:3 [▶]
#attributes: array:23 [▶]
#original: array:23 [▶]
}
public static function butuhdana($barang_id)
{
$storage = ItemStorage::where('id', $barang_id)->first();
$barang = $storage->submission;
}
Trying to get property 'submission' of non-object
答案 0 :(得分:0)
我遇到了问题,不仅仅是一个$ barang_id,还有更多
$("#slide_nominal").ionRangeSlider({
grid: true,
min: {!! \App\Service\Modular\BarangHelper::butuhdana($barang->storage->id) >= 100000 ? 100000 : \App\Service\Modular\BarangHelper::butuhdana($barang->storage->id) !!},
max: {!! \App\Service\Modular\BarangHelper::butuhdana($barang->storage->id) !!},
step: {!! \App\Service\Modular\BarangHelper::butuhdana($barang->storage->id) >= 100000 ? 50000 : \App\Service\Modular\BarangHelper::butuhdana($barang->storage->id) !!},
prettify_enabled: true,
prettify_separator: "."
});