AssetMaintenance.php
Go to the documentation of this file.
1 <?php
2 namespace App\Models;
3 
8 
14 class AssetMaintenance extends Model implements ICompanyableChild
15 {
16  use SoftDeletes;
18 
19 
20  protected $dates = [ 'deleted_at' ];
21  protected $table = 'asset_maintenances';
22 
23  // Declaring rules for form validation
24  protected $rules = [
25  'asset_id' => 'required|integer',
26  'supplier_id' => 'required|integer',
27  'asset_maintenance_type' => 'required',
28  'title' => 'required|max:100',
29  'is_warranty' => 'boolean',
30  'start_date' => 'required|date_format:Y-m-d',
31  'completion_date' => 'date_format:Y-m-d',
32  'notes' => 'string',
33  'cost' => 'numeric'
34  ];
35 
36  public function getCompanyableParents()
37  {
38  return [ 'asset' ];
39  }
40 
48  public static function getImprovementOptions()
49  {
50 
51  return [
52  Lang::get('admin/asset_maintenances/general.maintenance') => Lang::get('admin/asset_maintenances/general.maintenance'),
53  Lang::get('admin/asset_maintenances/general.repair') => Lang::get('admin/asset_maintenances/general.repair'),
54  Lang::get('admin/asset_maintenances/general.upgrade') => Lang::get('admin/asset_maintenances/general.upgrade')
55  ];
56  }
57 
66  public function asset()
67  {
68 
69  return $this->belongsTo('\App\Models\Asset', 'asset_id')
70  ->withTrashed();
71  }
72 
73  public function supplier()
74  {
75 
76  return $this->belongsTo('\App\Models\Supplier', 'supplier_id')
77  ->withTrashed();
78  }
79 
94  public function scopeDeleted($query)
95  {
96 
97  return $query->whereNotNull('deleted_at');
98  }
99 
108  public function scopeTextSearch($query, $search)
109  {
110 
111  return $query->where(function ($query) use ($search) {
112 
113  $query->where('title', 'LIKE', '%'.$search.'%')
114  ->orWhere('notes', 'LIKE', '%'.$search.'%')
115  ->orWhere('asset_maintenance_type', 'LIKE', '%'.$search.'%')
116  ->orWhere('cost', 'LIKE', '%'.$search.'%')
117  ->orWhere('start_date', 'LIKE', '%'.$search.'%')
118  ->orWhere('completion_date', 'LIKE', '%'.$search.'%');
119  });
120  }
121 }
scopeTextSearch($query, $search)
Query builder scope to search on text.
scopeDeleted($query)
BEGIN QUERY SCOPES
static getImprovementOptions()
getImprovementOptions
Model for Asset Maintenances.
asset()
asset Get asset for this improvement