Depreciation.php
Go to the documentation of this file.
1 <?php
2 namespace App\Models;
3 
6 
7 class Depreciation extends Model
8 {
9  // Declare the rules for the form validation
10  protected $rules = array(
11  'name' => 'required|min:3|max:255|unique:depreciations,name',
12  'months' => 'required|min:1|max:240|integer',
13  );
14 
22  protected $injectUniqueIdentifier = true;
23  use ValidatingTrait;
24 
30  protected $fillable = ['name','months'];
31 
32 
33 
34  public function has_models()
35  {
36  return $this->hasMany('\App\Models\AssetModel', 'depreciation_id')->count();
37  }
38 
39  public function has_licenses()
40  {
41  return $this->hasMany('\App\Models\License', 'depreciation_id')->count();
42  }
43 
52  public function scopeTextSearch($query, $search)
53  {
54 
55  return $query->where(function ($query) use ($search) {
56 
57  $query->where('name', 'LIKE', '%'.$search.'%')
58  ->orWhere('months', 'LIKE', '%'.$search.'%');
59  });
60  }
61 }
scopeTextSearch($query, $search)
Query builder scope to search on text.