我想直接使用它并且在控制器上时遇到问题
if(Promosi::where('kode',$kodepromo)->count() > 0):
$tambah = new Invoice();
$tambah->id_user = $request['id_user'];
$tambah->id = $id;
$tambah->id_invoice = $request['id_invoice'];
$tambah->item = 'Discout for Vendor';
$tambah->category = $kode->type;
$tambah->price = $potongan;
$tambah->type = 'debit';
$tambah->save();
return redirect()->to('/bill/'.$id);
else:
return redirect()->to('/bill/'.$id);
endif;
1/1)ErrorException尝试在HandleExceptions的HomeController.php第469行中获取非对象的属性-> handleError(8,'试图获取非对象的属性','D:\ xampp \ htdocs \ myfolder \ app \ Http \ Controllers \ HomeController.php',469,array('request'=> object(Request),'id'=>'a5804090-d97f-421b-8e38-6eddc02f4d62','kodepromo'=>'ffff ','kode'=> null,'themebill'=> object(Invoice),'price'=>'150000')))在HomeController.php第469行
答案 0 :(得分:0)
如果您手动设置了id
,则雄辩的ORM无法看到此信息,并尝试创建新记录。要更改此行为,请将$tambah->exists
设置为true,然后保存。
$tambah->exists = true;
$tambah->save();
如果$tambah->exists
为true,则ORM将使用MySQL update
,否则它将使用MySQL insert