Example #1
0
 /**
  * Store a newly created product in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Product::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $file = Input::file('image');
     $filename = str_random(12);
     $ext = Input::file('image')->getClientOriginalExtension();
     $photo = $filename . '.' . $ext;
     $destination = public_path() . '/uploads/images';
     Input::file('image')->move($destination, $photo);
     $vendor = Vendor::find(Input::get('vendor_id'));
     $product = new Product();
     $product->vendor()->associate($vendor);
     $product->name = Input::get('name');
     $product->image = $photo;
     $product->description = Input::get('description');
     $product->price = Input::get('price');
     $product->status = "active";
     $product->save();
     return Redirect::route('products.index');
 }