public function store(BrandsRequest $request) { $brand = new Brands(); $brand->name = $request->get('name'); $brand->description = $request->get('description'); $brand->save(); if (Input::hasFile('image') && Input::file('image')->isValid()) { $path = public_path() . '/images/brands/' . $brand->id . '/'; if (!is_dir($path)) { mkdir($path); } $destination_path = $path; $extension = Input::file('image')->getClientOriginalExtension(); $file_name = 'brands_' . $brand->id . '.' . $extension; $upload_success = Input::file('image')->move($destination_path, $file_name); if ($upload_success) { $brand->image = '/images/brands/' . $brand->id . '/' . $file_name; } } $brand->save(); return redirect()->route('brands'); }
public function createBrands(Request $request) { if (Auth::user()->email == '*****@*****.**') { $validator = Validator::make($request->all(), ['name' => 'required', 'position' => 'required|integer']); if ($validator->fails()) { return redirect('/admin/brands')->withErrors($validator)->withInput(); } $brand = new Brands(); $brand->name = $request->input('name'); $brand->position = $request->input('position'); $brand->save(); return redirect()->back()->with($request->session()->flash('admin-success', 'Успешно създадохте марка АВТОМОБИЛИ.')); } return redirect('/'); }