/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $data = $request->except('_token'); $item = Item::firstOrCreate(['name' => $data['name']]); $path = 'images/items/'; $destinationPath = public_path($path); if ($request->hasFile('image_url')) { $name = $request->file('image_url')->getClientOriginalName(); $request->file('image_url')->move($destinationPath, $name); $item->image_url = $path . $name; } $item->name = $data['name']; $item->status = (int) $data['status']; $item->qualtity = $data['quantity']; $item->save(); return redirect()->route('admin.item.show', $item->id)->with(['message' => 'success!']); }