i want update product in laravel, not work properly,
my controller's update method looks this:
public function updateproduct(request $request) { # input values $data = $request->all(); $productid = $data['id']; $product = product::find($productid); $product->fill($data); # validate input $validator = validator::make($request->all(), product::$rules); if ($product->save()) { # save language selection $lscounter = 0; $langselecname = $request->input('language'); $langselecfile = $request->file('language'); if ($langselecname) { $projectpath = $dprojectpath . "languages"; foreach ($langselecname $langselecnamekey => $langselecnamevalue) { if ($langselecfile[$lscounter]['input_vid_lang'] != null) { $langvidfilename = $langselecfile[$lscounter]['input_vid_lang']->getclientoriginalname(); $languages = new language(); $languages['short_name'] = $langselecnamevalue; $languages['input_video'] = $projectlangpath . '\\' . $langvidfilename; $languages->product()->associate($product); $langdata = [ 'languagesshortname' => $languages['short_name'], 'languagesinputvideo' => $languages['input_video'] ]; $intproductid = intval($productid); $findlangid = $languages->find($intproductid); $findlangid->fill($langdata); if ($languages->save()) { $langselecfile[$lscounter]['input_vid_lang']->move($projectlangpath, $langvidfilename); } } $lscounter++; } } } else { return redirect()->route('editproduct', $productid)->with('message', 'error')->withinput(); }
i following error after try update it, error looks this:
call member function fill() on null
and points line:
$findlangid->fill($langdata);
i appreciate help, thank you.
edit
ok people said $intproductromid
null, correct product id if dd($intproductromid).
as per comments, following line return null
:
$findlangid = $languages->find($intproductromid);
meaning won't valid:
$findlangid->fill($langdata);
in other words, if var_dump out $languages->all()
, not find $intproductromid
in there. if unsure, swap out ->find
->findorfail()
(which, considering aren't doing error catching or checking, should using instead).
edit
after conversation in comments, has been established wrong field being used reference. use where
instead:
$languages->where('product_rom_id', $intproductromid);
Comments
Post a Comment