public function prepareData()
 {
     $locality = new Locality();
     $locality->postal_code = '1920';
     $locality->city = 'Martigny';
     $locality->save();
     $locality = new Locality();
     $locality->postal_code = '1965';
     $locality->city = 'Savièse';
     $locality->save();
     $locality = new Locality();
     $locality->postal_code = '2300';
     $locality->city = 'Neuchâtel';
     $locality->save();
 }
 /**
  * Submit locality form
  */
 public function saveLocality()
 {
     if (Input::get('locality_id') != null) {
         //edit style
         $locality = Locality::find(Input::get('locality_id'));
     } else {
         //create style
         $locality = new Locality();
     }
     $parent_locality_id = null;
     if (Input::get('parent_locality') != null) {
         $parent_locality = Locality::find(Input::get('parent_locality_id'));
         if ($parent_locality) {
             $parent_locality_id = $parent_locality->id;
         }
     }
     $locality->name = Input::get('name');
     $locality->type = Input::get('type');
     $locality->locality_id = $parent_locality_id;
     $locality->latitude = Input::get('latitude');
     $locality->longitude = Input::get('longitude');
     $locality->code = Input::get('code');
     $locality->save();
     if (Input::hasFile('flag')) {
         $f = Input::file('flag');
         //Change the image name: s<number_of_service>-<filename>.
         $filename = 'locality-' . $locality->id . '-flag-' . $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, 'locality_id' => $locality->id, 'beer_id' => NULL);
         if ($locality->flag()) {
             $locality->flag()->fill($image)->save();
         } else {
             Image::create($image);
         }
     }
     return Redirect::back()->withMessage('Locality created correctly');
 }