Manufacturer.php
Go to the documentation of this file.
1 <?php
2 namespace App\Models;
3 
7 
8 class Manufacturer extends Model
9 {
10  use SoftDeletes;
11  protected $dates = ['deleted_at'];
12  protected $table = 'manufacturers';
13 
14  // Declare the rules for the form validation
15  protected $rules = array(
16  'name' => 'required|min:2|max:255|unique:manufacturers,name,NULL,deleted_at',
17  'user_id' => 'integer',
18  );
19 
27  protected $injectUniqueIdentifier = true;
28  use ValidatingTrait;
29 
35  protected $fillable = ['name'];
36 
37 
38 
39  public function has_models()
40  {
41  return $this->hasMany('\App\Models\AssetModel', 'manufacturer_id')->count();
42  }
43 
44  public function assets()
45  {
46  return $this->hasManyThrough('\App\Models\Asset', '\App\Models\AssetModel', 'manufacturer_id', 'model_id');
47  }
48 
57  public function scopeTextSearch($query, $search)
58  {
59 
60  return $query->where(function ($query) use ($search) {
61 
62  $query->where('name', 'LIKE', '%'.$search.'%');
63  });
64  }
65 }
scopeTextSearch($query, $search)
Query builder scope to search on text.