1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
8
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
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
|
|
|
]; |
23
|
|
|
|
24
|
|
|
public function getSummaryAttribute() |
25
|
|
|
{ |
26
|
|
|
return Str::words($this->details, 50); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function EquipmentType() |
30
|
|
|
{ |
31
|
|
|
return $this->hasManyThrough(EquipmentType::class, TechTipEquipment::class, 'tip_id', 'equip_id', 'tip_id', 'equip_id'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function FileUploads() |
35
|
|
|
{ |
36
|
|
|
return $this->hasManyThrough(FileUploads::class, TechTipFile::class, 'tip_id', 'file_id', 'tip_id', 'file_id'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function TechTipComment() |
40
|
|
|
{ |
41
|
|
|
return $this->hasMany(TechTipComment::class, 'tip_id', 'tip_id'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function CreatedBy() |
45
|
|
|
{ |
46
|
|
|
return $this->hasOne(User::class, 'user_id', 'user_id'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function UpdatedBy() |
50
|
|
|
{ |
51
|
|
|
return $this->hasOne(User::class, 'user_id', 'updated_id'); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|