php - Laravel inject data in input before store -
in store function in controller have:
public function store() { $validator = validator::make($data = input::all(), item::$rules); if ($validator->fails()) { return redirect::back()->witherrors($validator)->withinput(); } item::create($data); return redirect::route('spesas.index'); }
what missing user_id field.
i tought since inserting user auth one, not pass id via post, retrieve auth::user() in controller (it seemed more secure).
now have problem insert auth::user() id in input fields before item::create($data);
am doing right thing? suggestions?
thanks,
just add user id $data array doing:
$data['user_id'] = auth::user()->id;
simple that. :-)
alternatively, have hidden input field named 'user_id' , add authorised users id fields value. you.
Comments
Post a Comment