/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $item = new \App\Item(); $item->title = $request->title; $item->save(); return $item; }
public function createItem(Request $request, int $listId) { $name = $request->input('name'); $position = $request->input('position', 0); $custom = $request->input('custom', '{}'); if (empty($name)) { return $this->error('Name must be set'); } $item = new \App\Item(); $item->name = $name; $item->list_id = $listId; $item->position = $position; $item->custom = $custom; $result = $item->save(); if (empty($result)) { return $this->error('Failed to save item'); } return $this->read($listId); }
public function postAdd(Request $request) { $this->validate($request, ['name' => 'required|min:2']); $item = new \App\Item(); $item->name = $request->name; $item->amount = $request->amount; $item->user_id = \Auth::id(); $item->store_location = $request->store_location; $item->notes = $request->notes; $item->selected = $request->selected; $item->save(); if ($request->stores) { //Records the stores associated with each item... $stores = $request->stores; //Associaton is done through a pivot table } else { $stores = []; } $item->stores()->sync($stores); \Session::flash('flash_message', 'Your item was added!'); return redirect('/items'); }
public function postCreateItem(Request $request) { //Validate the request for the required feilds $this->validate($request, ['item_name' => 'required']); $item = new \App\Item(); $item->item_name = $request->item_name; $item->quantity = $request->item_qty; $item->store_aisle_num = $request->item_store_aisle; $item->store_id = $request->id; $item->save(); \Session::flash('flash_message', 'Item added to store!'); //return redirect('/store'); return redirect('/store/' . $item->store_id . '/items'); }