public function saving($model)
 {
     $travel_agent = new \App\TravelAgent();
     // RULES
     $rules['travel_agent_id'] = ['integer', 'min:1', 'exists:' . $travel_agent->getTable() . ',id'];
     $validator = Validator::make($model->toArray(), $rules);
     if ($validator->fails()) {
         $model->setErrors($validator->messages());
         return false;
     }
 }
Ejemplo n.º 2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $data = ['Panorama Tour', 'Smailing Tour', 'Dwidaya Tour', 'Kaha Tour', 'Avia Tour', 'Bayu Buana Tour'];
     //
     foreach ($data as $k => $x) {
         // TOUR
         $travel = new \App\TravelAgent();
         $travel->fill(['name' => $x, 'email' => 'book@' . strtolower(camel_case(str_replace(' ', '', $x))) . '.com', 'address' => 'Jl Jenderal Sudirman No 1 Jakarta', 'phone' => '021-' . rand(9000000, 9999999)]);
         if (!$travel->save()) {
             dd($travel->email . '' . $travel->getErrors());
         }
         // TOUR DESTINATION
         $travel->images()->saveMany([new \App\Image(['name' => 'SmallLogo', 'path' => 'http://localhost:8000/images/logo/' . ($k + 1) . '.png', 'title' => $x, 'description' => 'Logo ' . $x]), new \App\Image(['name' => 'LargeLogo', 'path' => 'http://localhost:8000/images/logo/' . ($k + 1) . '.png', 'title' => $x, 'description' => 'Logo ' . $x])]);
     }
 }
 public function saving($model)
 {
     $dest_model = new \App\TravelAgent();
     // RULES
     if (is_array($model->travel_agent_ids)) {
         foreach ($model->travel_agent_ids as $k => $v) {
             $rules['travel_agent_ids' . $k] = ['exists:' . $dest_model->getTable()];
         }
     } else {
         $rules['travel_agent_ids'] = ['exists:' . $dest_model->getTable()];
     }
     $validator = Validator::make($model->toArray(), $rules);
     if ($validator->fails()) {
         $model->setErrors($validator->messages());
         return false;
     }
 }