Model for Components. More...

Inheritance diagram for App\Models\Component:

Public Member Functions

 location ()
 
 assets ()
 
 admin ()
 
 company ()
 
 category ()
 
 assetlog ()
 Get action logs for this consumable. More...
 
 numRemaining ()
 
 scopeTextSearch ($query, $search)
 Query builder scope to search on text. More...
 
 scopeOrderCategory ($query, $order)
 Query builder scope to order on company. More...
 
 scopeOrderLocation ($query, $order)
 Query builder scope to order on company. More...
 
 scopeOrderCompany ($query, $order)
 Query builder scope to order on company. More...
 

Public Attributes

 $rules
 Category validation rules. More...
 

Protected Attributes

 $dates = ['deleted_at']
 
 $table = 'components'
 
 $injectUniqueIdentifier = true
 
 $fillable = ['name','company_id','category_id']
 

Detailed Description

Model for Components.

Version
v1.0

Definition at line 19 of file Component.php.

Member Function Documentation

App\Models\Component::admin ( )

Definition at line 63 of file Component.php.

64  {
65  return $this->belongsTo('\App\Models\User', 'user_id');
66  }
App\Models\Component::assetlog ( )

Get action logs for this consumable.

Definition at line 82 of file Component.php.

83  {
84  return $this->hasMany('\App\Models\Actionlog', 'component_id')->where('asset_type', '=', 'component')->orderBy('created_at', 'desc')->withTrashed();
85  }
App\Models\Component::assets ( )

Definition at line 58 of file Component.php.

59  {
60  return $this->belongsToMany('\App\Models\Asset', 'components_assets')->withPivot('assigned_qty', 'created_at', 'user_id');
61  }
App\Models\Component::category ( )

Definition at line 74 of file Component.php.

75  {
76  return $this->belongsTo('\App\Models\Category', 'category_id');
77  }
App\Models\Component::company ( )

Definition at line 68 of file Component.php.

69  {
70  return $this->belongsTo('\App\Models\Company', 'company_id');
71  }
App\Models\Component::location ( )

Definition at line 53 of file Component.php.

54  {
55  return $this->belongsTo('\App\Models\Location', 'location_id');
56  }
App\Models\Component::numRemaining ( )

Definition at line 88 of file Component.php.

89  {
90  $checkedout = 0;
91 
92  foreach ($this->assets as $checkout) {
93  $checkedout += $checkout->pivot->assigned_qty;
94  }
95 
96 
97  $total = $this->total_qty;
98  $remaining = $total - $checkedout;
99  return $remaining;
100  }
App\Models\Component::scopeOrderCategory (   $query,
  $order 
)

Query builder scope to order on company.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$orderOrder
Returns
Illuminate Modified query builder

Definition at line 152 of file Component.php.

153  {
154  return $query->join('categories', 'components.category_id', '=', 'categories.id')->orderBy('categories.name', $order);
155  }
App\Models\Component::scopeOrderCompany (   $query,
  $order 
)

Query builder scope to order on company.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$orderOrder
Returns
Illuminate Modified query builder

Definition at line 179 of file Component.php.

180  {
181  return $query->leftJoin('companies', 'components.company_id', '=', 'companies.id')->orderBy('companies.name', $order);
182  }
App\Models\Component::scopeOrderLocation (   $query,
  $order 
)

Query builder scope to order on company.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$orderOrder
Returns
Illuminate Modified query builder

Definition at line 165 of file Component.php.

166  {
167  return $query->leftJoin('locations', 'components.location_id', '=', 'locations.id')->orderBy('locations.name', $order);
168  }
App\Models\Component::scopeTextSearch (   $query,
  $search 
)

Query builder scope to search on text.

Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$searchSearch term
Returns
Illuminate Modified query builder Query builder scope to search on text
Parameters
Illuminate\Database\Query\Builder$queryQuery builder instance
text$searchSearch term
Returns
Illuminate Modified query builder

Definition at line 119 of file Component.php.

120  {
121  $search = explode(' ', $search);
122 
123  return $query->where(function ($query) use ($search) {
124 
125  foreach ($search as $search) {
126  $query->whereHas('category', function ($query) use ($search) {
127  $query->where('categories.name', 'LIKE', '%'.$search.'%');
128  })->orWhere(function ($query) use ($search) {
129  $query->whereHas('company', function ($query) use ($search) {
130  $query->where('companies.name', 'LIKE', '%'.$search.'%');
131  });
132  })->orWhere(function ($query) use ($search) {
133  $query->whereHas('location', function ($query) use ($search) {
134  $query->where('locations.name', 'LIKE', '%'.$search.'%');
135  });
136  })->orWhere('components.name', 'LIKE', '%'.$search.'%')
137  ->orWhere('components.order_number', 'LIKE', '%'.$search.'%')
138  ->orWhere('components.purchase_cost', 'LIKE', '%'.$search.'%')
139  ->orWhere('components.purchase_date', 'LIKE', '%'.$search.'%');
140  }
141  });
142  }

Member Data Documentation

App\Models\Component::$dates = ['deleted_at']
protected

Definition at line 24 of file Component.php.

App\Models\Component::$fillable = ['name','company_id','category_id']
protected

Definition at line 51 of file Component.php.

App\Models\Component::$injectUniqueIdentifier = true
protected

Definition at line 43 of file Component.php.

App\Models\Component::$rules
Initial value:
= array(
'name' => 'required|min:3|max:255',
'min_amt' => 'integer|min:1',
)

Category validation rules.

Definition at line 31 of file Component.php.

App\Models\Component::$table = 'components'
protected

Definition at line 25 of file Component.php.


The documentation for this class was generated from the following file: