Statuslabel.php
Go to the documentation of this file.
1 <?php
2 namespace App\Models;
3 
7 
8 class Statuslabel extends Model
9 {
10  use SoftDeletes;
11  use ValidatingTrait;
12 
13  protected $injectUniqueIdentifier = true;
14  protected $dates = ['deleted_at'];
15  protected $table = 'status_labels';
16 
17 
18  protected $rules = array(
19  'name' => 'required|string|unique:status_labels,name,NULL,deleted_at',
20  //'statuslabel_types' => 'required|in:deployable,pending,archived,undeployable',
21  'notes' => 'string',
22  );
23 
24  protected $fillable = ['name'];
25 
26  public function has_assets()
27  {
28  return $this->hasMany('\App\Models\Asset', 'status_id')->count();
29  }
30 
31  public function getStatuslabelType()
32  {
33 
34  if ($this->pending == 1) {
35  return 'pending';
36  } elseif ($this->archived == 1) {
37  return 'archived';
38  } elseif (($this->archived == 0) && ($this->deployable == 0) && ($this->deployable == 0)) {
39  return 'undeployable';
40  } else {
41  return 'deployable';
42  }
43  }
44 
45  public static function getStatuslabelTypesForDB($type)
46  {
47  if ($type == 'pending') {
48  $statustype['pending'] = 1;
49  $statustype['deployable'] = 0;
50  $statustype['archived'] = 0;
51 
52  } elseif ($type == 'deployable') {
53  $statustype['pending'] = 0;
54  $statustype['deployable'] = 1;
55  $statustype['archived'] = 0;
56 
57  } elseif ($type == 'archived') {
58  $statustype['pending'] = 0;
59  $statustype['deployable'] = 0;
60  $statustype['archived'] = 1;
61 
62  } elseif ($type == 'undeployable') {
63  $statustype['pending'] = 0;
64  $statustype['deployable'] = 0;
65  $statustype['archived'] = 0;
66  }
67 
68  return $statustype;
69  }
70 
79  public function scopeTextSearch($query, $search)
80  {
81 
82  return $query->where(function ($query) use ($search) {
83 
84  $query->where('name', 'LIKE', '%'.$search.'%');
85  });
86  }
87 }
scopeTextSearch($query, $search)
Query builder scope to search on text.
Definition: Statuslabel.php:79
static getStatuslabelTypesForDB($type)
Definition: Statuslabel.php:45