Пример #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $skills = Skill::lists('id');
     $last = count($skills) - 1;
     $faker = new Faker\Generator();
     for ($i = 0; $i < 1; $i++) {
         $certificate = Certificate::create(['title' => 'PHP Master', 'length' => '300 hours', 'certified_by' => 'My Friend']);
         if (count($skills)) {
             $certificate->skills()->attach($skills[rand(0, $last)]);
         }
     }
 }
Пример #2
0
 public function update(Certificate $certificate, array $data)
 {
     \DB::beginTransaction();
     try {
         $skills = $data['skills_ids'];
         unset($data['skills_ids']);
         if ($skills == NULL) {
             $certificate->skills()->sync([]);
         } else {
             if (!is_array($skills)) {
                 $skills = explode(',', $skills);
             }
             $certificate->skills()->sync($skills);
         }
         $certificate->save();
         \DB::commit();
         return $certificate;
     } catch (\Exception $e) {
         \DB::rollback();
         throw $e;
     }
 }