コード例 #1
0
 public function create($data)
 {
     $model = $this->getModel();
     $model->fill(['company_id' => $data['company_id'], 'agency_id' => isset($data['agency_id']) ? $data['agency_id'] : null, 'experience_year' => $data['experience_year'], 'start_date' => $data['start_date'], 'title' => $data['title'], 'city' => $data['city'], 'country' => $data['country'], 'duration' => isset($data['job_post_duration']) ? $data['job_post_duration'] : 999, 'contact_name' => $data['contact_name'], 'contact_phone' => $data['contact_phone'], 'salary' => $data['salary'], 'salary_type' => $data['salary_type'], 'visa' => $data['visa'] ? 1 : 0, 'eligible_to_work_in_country' => isset($data['eligible_to_work_in_country']) ? 1 : 0, 'security_clearance' => isset($data['security_clearance']) ? 1 : 0, 'type' => $data['type'], 'status' => 'open', 'job_apply_details' => $data['job_apply_details'], 'description' => $data['description']]);
     if ($model->save()) {
         $industryProvider = new JobIndustryProvider();
         foreach ($data['job_industry'] as $d) {
             $industry = $industryProvider->findById($d);
             if ($industry) {
                 $model->industries()->attach($industry->id, ['created_at' => Carbon::now()]);
             }
         }
         $contractors = \Contractor::findAllByJobAlerts($model, $data['job_industry']);
         if (count($contractors) > 0) {
             $_hash = new Hash();
             $_hash = $_hash->getHasher();
             foreach ($contractors as $contractor) {
                 if ($contractor->pivot->type === 'any' || $contractor->pivot->type === $model->type) {
                     $notificationData = ['contractor_id' => $contractor->id, 'alert_from' => 'System: Programme Chameleon', 'has_read' => false, 'title' => 'A new job matching your job alert found.', 'url' => url('job/' . $_hash->encode($model->id) . '/' . Str::slug($model->title))];
                     $notification = \Contractor::addNotification($contractor, $notificationData);
                 }
             }
         }
         return $model;
     } else {
         throw new \Exception("Error Processing Request", 1);
     }
     return;
 }