fixed #30
This commit is contained in:
parent
f04f596310
commit
55b09c9741
@ -26,7 +26,7 @@ class Item extends Model
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $sortable = ['name', 'category_id', 'quantity', 'sale_price', 'purchase_price', 'enabled'];
|
protected $sortable = ['name', 'category', 'quantity', 'sale_price', 'purchase_price', 'enabled'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searchable rules.
|
* Searchable rules.
|
||||||
@ -116,4 +116,19 @@ class Item extends Model
|
|||||||
|
|
||||||
return $query->get();
|
return $query->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort by category name
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
|
* @param $direction
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public function categorySortable($query, $direction)
|
||||||
|
{
|
||||||
|
return $query->join('categories', 'categories.id', '=', 'items.category_id')
|
||||||
|
->orderBy('name', $direction)
|
||||||
|
->select('items.*');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th class="col-md-1">{{ trans_choice('general.pictures', 1) }}</th>
|
<th class="col-md-1">{{ trans_choice('general.pictures', 1) }}</th>
|
||||||
<th class="col-md-3">@sortablelink('name', trans('general.name'))</th>
|
<th class="col-md-3">@sortablelink('name', trans('general.name'))</th>
|
||||||
<th class="col-md-1">@sortablelink('category.name', trans_choice('general.categories', 1))</th>
|
<th class="col-md-1">@sortablelink('category', trans_choice('general.categories', 1))</th>
|
||||||
<th class="col-md-1">@sortablelink('quantity', trans_choice('items.quantities', 1))</th>
|
<th class="col-md-1">@sortablelink('quantity', trans_choice('items.quantities', 1))</th>
|
||||||
<th>@sortablelink('sale_price', trans('items.sales_price'))</th>
|
<th>@sortablelink('sale_price', trans('items.sales_price'))</th>
|
||||||
<th>@sortablelink('purchase_price', trans('items.purchase_price'))</th>
|
<th>@sortablelink('purchase_price', trans('items.purchase_price'))</th>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user