示例#1
0
 /**
  * Store a newly created resource in storage.
  * POST /brewer
  *
  * @return Response
  */
 public function store()
 {
     if (Input::get('brewer_id')) {
         $brewer = Brewer::find(Input::get('brewer_id'));
     } else {
         $brewer = new Brewer();
     }
     $locality = Locality::find(Input::get('locality_id'));
     if (!$locality) {
         return Redirect::back()->withInput()->withMessage('Invalid Locality');
     }
     $brewer->name = Input::get('name');
     $brewer->url = Input::get('url');
     $brewer->locality_id = $locality->id;
     $brewer->save();
     if (Input::hasFile('logo')) {
         $f = Input::file('logo');
         //Change the image name: s<number_of_service>-<filename>.
         $filename = 'brewer-' . $brewer->id . '-' . $f->getClientOriginalName();
         //Move it to our public folder
         $f->move(public_path() . '/upload/', $filename);
         //This is the path to show it on the web
         $complete_path = '/upload/' . $filename;
         //create the gallery
         $image = array('path' => $complete_path, 'brewer_id' => $brewer->id, 'beer_id' => NULL);
         if ($brewer->logoUrl()) {
             $brewer->logo()->fill($image)->save();
         } else {
             Image::create($image);
         }
     }
     return Redirect::to('/dashboard/brewers');
 }