Trying to get property of non-object laravel? -
i beginner. i'm trying fix, think need help.
-this code controller
if(input::hasfile('image')){ $dest = 'media/images/product/'; $name = str_random(6).'_'.input::file('image')->getclientoriginalname(); //$resize = input::file('image')->move($dest,$name); } $loaispname = input::get('loaispname'); $loaisp = new loaisp; $datas = $loaisp->getidloaisp($loaispname); $idloaisp = $datas->id; $item = new sanpham; $item->loaisp_id = $idloaisp; $item->sanpham_name = input::get('sanpham'); $item->sanpham_img = $name; $item->sanpham_tieude = input::get('tieude'); $item->sanpham_gia = input::get('gia'); $item->sanpham_chitiet = input::get('chitiet'); $item->sanpham_vitri = input::get('vitri'); $item->save(); return redirect::to('admin/dsachsanpham')->with('thanhcong','saved');
-this code model
public function getidloaisp($loaispname){ //return loaisp::where('loaisp_name','=',$loaispname)->get(); return db::table('loaisp')->where('loaisp_name',$loaispname)->first(); }
-this error
errorexception (e_unknown) trying property of non-object open: e:\xampp\htdocs\www\daunhot\app\controllers\admincontroller.php
$loaispname = input::get('loaispname'); $loaisp = new loaisp; $datas = $loaisp->getidloaisp($loaispname); $idloaisp = $datas->id; // error $item = new sanpham;
when see error there 2 error: got nothing query(db::table('loaisp')->where('loaisp_name',$loaispname)->first();), or got array, if using ->get() instead of ->first() error. try use foreach on query result, or try use dd() function on result can see if empty or not. if empty porblem.
Comments
Post a Comment