1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
8
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
9
|
|
|
|
10
|
|
|
class TechTip extends Model |
11
|
|
|
{ |
12
|
|
|
use HasFactory; |
13
|
|
|
use SoftDeletes; |
14
|
|
|
|
15
|
|
|
protected $primaryKey = 'tip_id'; |
16
|
|
|
protected $guarded = ['tip_id', 'created_at', 'updated_at']; |
17
|
|
|
protected $hidden = ['deleted_at', 'tip_type_id', 'updated_id', 'user_id']; |
18
|
|
|
protected $appends = ['summary']; |
19
|
|
|
protected $casts = [ |
20
|
|
|
'created_at' => 'datetime:M d, Y', |
21
|
|
|
'updated_at' => 'datetime:M d, Y', |
22
|
|
|
'deleted_at' => 'datetime:M d, Y', |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
public function getSummaryAttribute() |
26
|
|
|
{ |
27
|
|
|
return Str::words($this->details, 50); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function EquipmentType() |
31
|
|
|
{ |
32
|
|
|
return $this->hasManyThrough(EquipmentType::class, TechTipEquipment::class, 'tip_id', 'equip_id', 'tip_id', 'equip_id'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function FileUploads() |
36
|
|
|
{ |
37
|
|
|
return $this->hasManyThrough(FileUploads::class, TechTipFile::class, 'tip_id', 'file_id', 'tip_id', 'file_id'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function TechTipComment() |
41
|
|
|
{ |
42
|
|
|
return $this->hasMany(TechTipComment::class, 'tip_id', 'tip_id'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function CreatedBy() |
46
|
|
|
{ |
47
|
|
|
return $this->hasOne(User::class, 'user_id', 'user_id'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function UpdatedBy() |
51
|
|
|
{ |
52
|
|
|
return $this->hasOne(User::class, 'user_id', 'updated_id'); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|