Supplier.php
Go to the documentation of this file.
1 <?php
2 namespace App\Models;
3 
7 
8 class Supplier extends Model
9 {
10  use SoftDeletes;
11  protected $dates = ['deleted_at'];
12 
13  protected $rules = array(
14  'name' => 'required|min:3|max:255|unique:suppliers,name,NULL,deleted_at',
15  'address' => 'min:3|max:255',
16  'address2' => 'min:2|max:255',
17  'city' => 'min:3|max:255',
18  'state' => 'min:0|max:32',
19  'country' => 'min:0|max:2',
20  'fax' => 'min:7|max:20',
21  'phone' => 'min:7|max:20',
22  'contact' => 'min:0|max:255',
23  'notes' => 'min:0|max:255',
24  'email' => 'email|min:5|max:150',
25  'zip' => 'min:0|max:10',
26  'url' => 'min:3|max:250',
27  );
28 
36  protected $injectUniqueIdentifier = true;
37  use ValidatingTrait;
38 
44  protected $fillable = ['name'];
45 
46 
47  public function assets()
48  {
49  return $this->hasMany('\App\Models\Asset', 'supplier_id');
50  }
51 
52  public function asset_maintenances()
53  {
54  return $this->hasMany('\App\Models\AssetMaintenance', 'supplier_id');
55  }
56 
57  public function num_assets()
58  {
59  return $this->hasMany('\App\Models\Asset', 'supplier_id')->count();
60  }
61 
62  public function licenses()
63  {
64  return $this->hasMany('\App\Models\License', 'supplier_id');
65  }
66 
67  public function num_licenses()
68  {
69  return $this->hasMany('\App\Models\License', 'supplier_id')->count();
70  }
71 
72  public function addhttp($url)
73  {
74  if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
75  $url = "http://" . $url;
76  }
77  return $url;
78  }
79 
88  public function scopeTextSearch($query, $search)
89  {
90 
91  return $query->where(function ($query) use ($search) {
92 
93  $query->where('name', 'LIKE', '%'.$search.'%');
94  });
95  }
96 }
scopeTextSearch($query, $search)
Query builder scope to search on text.
Definition: Supplier.php:88