Employer.php
2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Employer extends Model
{
use HasFactory;
protected $fillable = [
'name_company',
'email',
'telephone',
'logo',
'rate',
'user_id',
'sort',
'text',
'address',
'map',
'site',
'coord',
'plus',
'is_remove',
'oficial_status',
'social_is',
'sending_is',
'category',
'comment_admin',
'code',
'status_hidden',
'email_2',
'telephone_2',
'autoresponder',
'autoresponder_message',
'autolift_options',
];
protected function autoliftOptions(): Attribute
{
$template = [
'times_per_day' => null,
'days_repeat' => null,
'time_send_first' => null,
'time_send_second' => null,
'time_send_third' => null,
'time_send_tg' => null,
];
return Attribute::make(
get: fn ($value) => $value === null ? $template : json_decode($value, true, 512, JSON_THROW_ON_ERROR),
set: fn ($value) => json_encode($value, JSON_THROW_ON_ERROR)
);
}
/*
* Связь таблицы users с таблицей employers
*/
public function users() {
return $this->belongsTo(User::class, 'user_id');
}
/*
* Связь Работодателя с вакансиями
*/
public function ads(): HasMany
{
return $this->hasMany(Ad_employer::class);
}
// связь Работодателя с флотом
public function flots(){
return $this->hasMany(Flot::class);
}
// связь Работодателя с Должностями в Вакансиях
//public function ad_jobs() {
// return $this->belongsToMany(Ad_jobs::class, 'ad_employers');
//}
public function scopeActive($query) {
return $query->where('is_remove', '=', '0');
}
}