mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 06:17:28 -08:00
Added ->with(‘users as users_count’)
in Accessory query
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
90c1631820
commit
60eab08735
|
@ -127,45 +127,45 @@ class AccessoriesController extends Controller
|
||||||
*/
|
*/
|
||||||
public function update(ImageUploadRequest $request, $accessoryId = null)
|
public function update(ImageUploadRequest $request, $accessoryId = null)
|
||||||
{
|
{
|
||||||
if (is_null($accessory = Accessory::find($accessoryId))) {
|
if ($accessory = Accessory::withCount('users as users_count')->find($accessoryId)) {
|
||||||
|
|
||||||
|
$validator = Validator::make($request->all(), [
|
||||||
|
"qty" => "required|numeric|min:$accessory->users_count"
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
return redirect()->back()
|
||||||
|
->withErrors($validator)
|
||||||
|
->withInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->authorize($accessory);
|
||||||
|
|
||||||
|
// Update the accessory data
|
||||||
|
$accessory->name = request('name');
|
||||||
|
$accessory->location_id = request('location_id');
|
||||||
|
$accessory->min_amt = request('min_amt');
|
||||||
|
$accessory->category_id = request('category_id');
|
||||||
|
$accessory->company_id = Company::getIdForCurrentUser(request('company_id'));
|
||||||
|
$accessory->manufacturer_id = request('manufacturer_id');
|
||||||
|
$accessory->order_number = request('order_number');
|
||||||
|
$accessory->model_number = request('model_number');
|
||||||
|
$accessory->purchase_date = request('purchase_date');
|
||||||
|
$accessory->purchase_cost = Helper::ParseCurrency(request('purchase_cost'));
|
||||||
|
$accessory->qty = request('qty');
|
||||||
|
$accessory->supplier_id = request('supplier_id');
|
||||||
|
$accessory->notes = request('notes');
|
||||||
|
|
||||||
|
$accessory = $request->handleImages($accessory);
|
||||||
|
|
||||||
|
// Was the accessory updated?
|
||||||
|
if ($accessory->save()) {
|
||||||
|
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.update.success'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
|
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$min = $accessory->numCheckedOut();
|
|
||||||
$validator = Validator::make($request->all(), [
|
|
||||||
"qty" => "required|numeric|min:$min"
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($validator->fails()) {
|
|
||||||
return redirect()->back()
|
|
||||||
->withErrors($validator)
|
|
||||||
->withInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->authorize($accessory);
|
|
||||||
|
|
||||||
// Update the accessory data
|
|
||||||
$accessory->name = request('name');
|
|
||||||
$accessory->location_id = request('location_id');
|
|
||||||
$accessory->min_amt = request('min_amt');
|
|
||||||
$accessory->category_id = request('category_id');
|
|
||||||
$accessory->company_id = Company::getIdForCurrentUser(request('company_id'));
|
|
||||||
$accessory->manufacturer_id = request('manufacturer_id');
|
|
||||||
$accessory->order_number = request('order_number');
|
|
||||||
$accessory->model_number = request('model_number');
|
|
||||||
$accessory->purchase_date = request('purchase_date');
|
|
||||||
$accessory->purchase_cost = Helper::ParseCurrency(request('purchase_cost'));
|
|
||||||
$accessory->qty = request('qty');
|
|
||||||
$accessory->supplier_id = request('supplier_id');
|
|
||||||
$accessory->notes = request('notes');
|
|
||||||
|
|
||||||
$accessory = $request->handleImages($accessory);
|
|
||||||
|
|
||||||
// Was the accessory updated?
|
|
||||||
if ($accessory->save()) {
|
|
||||||
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.update.success'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect()->back()->withInput()->withErrors($accessory->getErrors());
|
return redirect()->back()->withInput()->withErrors($accessory->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ class AccessoriesController extends Controller
|
||||||
*/
|
*/
|
||||||
public function show($accessoryID = null)
|
public function show($accessoryID = null)
|
||||||
{
|
{
|
||||||
$accessory = Accessory::find($accessoryID);
|
$accessory = Accessory::withCount('users as users_count')->find($accessoryID);
|
||||||
$this->authorize('view', $accessory);
|
$this->authorize('view', $accessory);
|
||||||
if (isset($accessory->id)) {
|
if (isset($accessory->id)) {
|
||||||
return view('accessories/view', compact('accessory'));
|
return view('accessories/view', compact('accessory'));
|
||||||
|
|
|
@ -41,10 +41,13 @@ class AccessoriesController extends Controller
|
||||||
'min_amt',
|
'min_amt',
|
||||||
'company_id',
|
'company_id',
|
||||||
'notes',
|
'notes',
|
||||||
|
'users_count',
|
||||||
|
'qty',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
$accessories = Accessory::select('accessories.*')->with('category', 'company', 'manufacturer', 'users', 'location', 'supplier');
|
$accessories = Accessory::select('accessories.*')->with('category', 'company', 'manufacturer', 'users', 'location', 'supplier')
|
||||||
|
->withCount('users as users_count');
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
$accessories = $accessories->TextSearch($request->input('search'));
|
$accessories = $accessories->TextSearch($request->input('search'));
|
||||||
|
|
Loading…
Reference in a new issue