@@ -38,6 +38,7 @@ class Component extends SnipeModel
3838 'min_amt ' => 'integer|min:0|nullable ' ,
3939 'purchase_date ' => 'date_format:Y-m-d|nullable ' ,
4040 'purchase_cost ' => 'numeric|nullable|gte:0|max:9999999999999 ' ,
41+ 'manufacturer_id ' => 'integer|exists:manufacturers,id|nullable ' ,
4142 ];
4243
4344 /**
@@ -60,6 +61,8 @@ class Component extends SnipeModel
6061 'company_id ' ,
6162 'supplier_id ' ,
6263 'location_id ' ,
64+ 'manufacturer_id ' ,
65+ 'model_number ' ,
6366 'name ' ,
6467 'purchase_cost ' ,
6568 'purchase_date ' ,
@@ -77,7 +80,15 @@ class Component extends SnipeModel
7780 *
7881 * @var array
7982 */
80- protected $ searchableAttributes = ['name ' , 'order_number ' , 'serial ' , 'purchase_cost ' , 'purchase_date ' , 'notes ' ];
83+ protected $ searchableAttributes = [
84+ 'name ' ,
85+ 'order_number ' ,
86+ 'serial ' ,
87+ 'purchase_cost ' ,
88+ 'purchase_date ' ,
89+ 'notes ' ,
90+ 'model_number ' ,
91+ ];
8192
8293 /**
8394 * The relations and their attributes that should be included when searching the model.
@@ -89,6 +100,7 @@ class Component extends SnipeModel
89100 'company ' => ['name ' ],
90101 'location ' => ['name ' ],
91102 'supplier ' => ['name ' ],
103+ 'manufacturer ' => ['name ' ],
92104 ];
93105
94106
@@ -183,6 +195,19 @@ public function supplier()
183195 return $ this ->belongsTo (\App \Models \Supplier::class, 'supplier_id ' );
184196 }
185197
198+
199+ /**
200+ * Establishes the item -> manufacturer relationship
201+ *
202+ * @author [A. Gianotto] [<[email protected] >] 203+ * @since [v3.0]
204+ * @return \Illuminate\Database\Eloquent\Relations\Relation
205+ */
206+ public function manufacturer ()
207+ {
208+ return $ this ->belongsTo (\App \Models \Manufacturer::class, 'manufacturer_id ' );
209+ }
210+
186211 /**
187212 * Establishes the component -> action logs relationship
188213 *
@@ -311,6 +336,19 @@ public function scopeOrderSupplier($query, $order)
311336 return $ query ->leftJoin ('suppliers ' , 'components.supplier_id ' , '= ' , 'suppliers.id ' )->orderBy ('suppliers.name ' , $ order );
312337 }
313338
339+ /**
340+ * Query builder scope to order on manufacturer
341+ *
342+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
343+ * @param text $order Order
344+ *
345+ * @return \Illuminate\Database\Query\Builder Modified query builder
346+ */
347+ public function scopeOrderManufacturer ($ query , $ order )
348+ {
349+ return $ query ->leftJoin ('manufacturers ' , 'components.manufacturer_id ' , '= ' , 'manufacturers.id ' )->orderBy ('manufacturers.name ' , $ order );
350+ }
351+
314352 public function scopeOrderByCreatedBy ($ query , $ order )
315353 {
316354 return $ query ->leftJoin ('users as admin_sort ' , 'components.created_by ' , '= ' , 'admin_sort.id ' )->select ('components.* ' )->orderBy ('admin_sort.first_name ' , $ order )->orderBy ('admin_sort.last_name ' , $ order );
0 commit comments