76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class JobPost extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected static function booted()
|
|
{
|
|
static::updated(function ($jobPost) {
|
|
if ($jobPost->wasChanged('status')) {
|
|
$oldStatus = $jobPost->getOriginal('status');
|
|
$newStatus = $jobPost->status;
|
|
|
|
// Send push notification to all workers who applied to this job
|
|
$applications = $jobPost->applications()->with('worker')->get();
|
|
foreach ($applications as $app) {
|
|
$worker = $app->worker;
|
|
if ($worker) {
|
|
$worker->notify(new \App\Notifications\GenericNotification(
|
|
"Job Status Changed",
|
|
"The status of the job '" . $jobPost->title . "' has been changed from '" . ucfirst($oldStatus) . "' to '" . ucfirst($newStatus) . "'.",
|
|
[
|
|
'type' => 'job_status_change',
|
|
'job_id' => $jobPost->id,
|
|
'old_status' => $oldStatus,
|
|
'new_status' => $newStatus,
|
|
]
|
|
));
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
protected $fillable = [
|
|
'employer_id',
|
|
'title',
|
|
'main_profession',
|
|
'workers_needed',
|
|
'job_type',
|
|
'location',
|
|
'salary',
|
|
'start_date',
|
|
'description',
|
|
'requirements',
|
|
'status',
|
|
];
|
|
|
|
protected $casts = [
|
|
'start_date' => 'date',
|
|
'salary' => 'decimal:2',
|
|
'workers_needed' => 'integer',
|
|
];
|
|
|
|
public function employer()
|
|
{
|
|
return $this->belongsTo(User::class, 'employer_id');
|
|
}
|
|
|
|
public function skills()
|
|
{
|
|
return $this->belongsToMany(Skill::class, 'job_post_skills', 'job_post_id', 'skill_id');
|
|
}
|
|
|
|
public function applications()
|
|
{
|
|
return $this->hasMany(JobApplication::class, 'job_id');
|
|
}
|
|
}
|