在laravel控制器中从空值创建默认对象

时间:2019-01-05 06:00:41

标签: laravel laravel-5

当我尝试使用波纹管控制器功能时,出现从空值创建默认对象的错误,我该如何解决?

savemed($id,$pid,$tid){
    $meds=TemporyMed::all();

    foreach($meds as $med){

    $issued_medicine=new IssuedMedicine();
    $issued_medicines->treatments_id=$tid;
    $issued_medicines->type=$med->type;
    $issued_medicines->quantity=$med->quantity;
    $issued_medicines->price=$med->price;
    $issued_medicines->save();


 }

 TemporyMed::all()->delete();

}

1 个答案:

答案 0 :(得分:0)

您在$issued_medicine=new IssuedMedicine();中出错。因此,只需将$issued_medicine=new IssuedMedicine();更改为$issued_medicines=new IssuedMedicine();,它将起作用