2018-10-19 07:30:25 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
use App\Helpers\Helper;
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Http\Controllers\Controller;
|
2018-10-19 07:30:25 -07:00
|
|
|
use App\Http\Transformers\PredefinedKitsTransformer;
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Models\PredefinedKit;
|
|
|
|
use Illuminate\Http\Request;
|
2018-10-19 07:30:25 -07:00
|
|
|
|
2019-02-23 11:44:03 -08:00
|
|
|
/**
|
|
|
|
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
|
|
|
*/
|
2018-10-19 07:30:25 -07:00
|
|
|
class PredefinedKitsController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
$this->authorize('view', PredefinedKit::class);
|
|
|
|
$allowed_columns = ['id', 'name'];
|
|
|
|
|
|
|
|
$kits = PredefinedKit::query();
|
|
|
|
|
|
|
|
if ($request->filled('search')) {
|
|
|
|
$kits = $kits->TextSearch($request->input('search'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$offset = $request->input('offset', 0);
|
|
|
|
$limit = $request->input('limit', 50);
|
|
|
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
|
|
|
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'assets_count';
|
|
|
|
$kits->orderBy($sort, $order);
|
|
|
|
|
|
|
|
$total = $kits->count();
|
|
|
|
$kits = $kits->skip($offset)->take($limit)->get();
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
return (new PredefinedKitsTransformer)->transformPredefinedKits($kits, $total);
|
2018-10-19 07:30:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$this->authorize('create', PredefinedKit::class);
|
|
|
|
$kit = new PredefinedKit;
|
|
|
|
$kit->fill($request->all());
|
|
|
|
|
|
|
|
if ($kit->save()) {
|
2019-03-13 12:15:48 -07:00
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, trans('admin/kits/general.create_success')));
|
2018-10-19 07:30:25 -07:00
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
return response()->json(Helper::formatStandardApiResponse('error', null, $kit->getErrors()));
|
2018-10-19 07:30:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
|
|
|
$this->authorize('view', PredefinedKit::class);
|
|
|
|
$kit = PredefinedKit::findOrFail($id);
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2018-10-31 06:06:38 -07:00
|
|
|
return (new PredefinedKitsTransformer)->transformPredefinedKit($kit);
|
2018-10-19 07:30:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2019-02-23 11:44:03 -08:00
|
|
|
* @param int $id kit id
|
2018-10-19 07:30:25 -07:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
|
|
|
$kit = PredefinedKit::findOrFail($id);
|
|
|
|
$kit->fill($request->all());
|
|
|
|
|
|
|
|
if ($kit->save()) {
|
2019-03-13 12:15:48 -07:00
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, trans('admin/kits/general.update_success'))); // TODO: trans
|
2018-10-19 07:30:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('error', null, $kit->getErrors()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
$this->authorize('delete', PredefinedKit::class);
|
|
|
|
$kit = PredefinedKit::findOrFail($id);
|
|
|
|
|
2019-02-19 11:19:00 -08:00
|
|
|
// Delete childs
|
|
|
|
$kit->models()->detach();
|
|
|
|
$kit->licenses()->detach();
|
|
|
|
$kit->consumables()->detach();
|
|
|
|
$kit->accessories()->detach();
|
|
|
|
|
2018-10-19 07:30:25 -07:00
|
|
|
$kit->delete();
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/kits/general.delete_success'))); // TODO: trans
|
2018-10-19 07:30:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a paginated collection for the select2 menus
|
|
|
|
*
|
|
|
|
* @see \App\Http\Transformers\SelectlistTransformer
|
|
|
|
*/
|
|
|
|
public function selectlist(Request $request)
|
|
|
|
{
|
|
|
|
$kits = PredefinedKit::select([
|
|
|
|
'id',
|
2021-06-10 13:15:52 -07:00
|
|
|
'name',
|
2018-10-19 07:30:25 -07:00
|
|
|
]);
|
|
|
|
|
|
|
|
if ($request->filled('search')) {
|
|
|
|
$kits = $kits->where('name', 'LIKE', '%'.$request->get('search').'%');
|
|
|
|
}
|
|
|
|
|
|
|
|
$kits = $kits->orderBy('name', 'ASC')->paginate(50);
|
|
|
|
|
|
|
|
return (new SelectlistTransformer)->transformSelectlist($kits);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function indexLicenses($kit_id)
|
|
|
|
{
|
2018-10-19 07:30:25 -07:00
|
|
|
$this->authorize('view', PredefinedKit::class);
|
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
|
|
|
$licenses = $kit->licenses;
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2018-10-19 07:30:25 -07:00
|
|
|
return (new PredefinedKitsTransformer)->transformElements($licenses, $licenses->count());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-23 11:44:03 -08:00
|
|
|
* Store the specified resource.
|
2018-10-19 07:30:25 -07:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function storeLicense(Request $request, $kit_id)
|
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
|
|
|
|
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
|
|
|
$quantity = $request->input('quantity', 1);
|
|
|
|
if ($quantity < 1) {
|
|
|
|
$quantity = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$license_id = $request->get('license');
|
|
|
|
$relation = $kit->licenses();
|
|
|
|
if ($relation->find($license_id)) {
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('error', null, ['license' => 'License already attached to kit']));
|
|
|
|
}
|
|
|
|
|
|
|
|
$relation->attach($license_id, ['quantity' => $quantity]);
|
|
|
|
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'License added successfull')); // TODO: trans
|
2018-10-19 07:30:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2019-02-27 14:37:58 -08:00
|
|
|
* @param int $kit_id
|
2018-10-19 07:30:25 -07:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function updateLicense(Request $request, $kit_id, $license_id)
|
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
|
|
|
$quantity = $request->input('quantity', 1);
|
|
|
|
if ($quantity < 1) {
|
|
|
|
$quantity = 1;
|
|
|
|
}
|
|
|
|
$kit->licenses()->syncWithoutDetaching([$license_id => ['quantity' => $quantity]]);
|
|
|
|
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'License updated')); // TODO: trans
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-19 07:30:25 -07:00
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $kit_id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2018-11-06 08:27:28 -08:00
|
|
|
public function detachLicense($kit_id, $license_id)
|
2018-10-19 07:30:25 -07:00
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
2019-02-27 14:37:58 -08:00
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
2018-10-19 07:30:25 -07:00
|
|
|
|
|
|
|
$kit->licenses()->detach($license_id);
|
2021-06-10 13:15:52 -07:00
|
|
|
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, trans('admin/kits/general.delete_success')));
|
2018-10-19 07:30:25 -07:00
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2018-10-19 07:30:25 -07:00
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2019-02-27 14:37:58 -08:00
|
|
|
* @param int $kit_id
|
2018-10-19 07:30:25 -07:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function indexModels($kit_id)
|
|
|
|
{
|
2018-10-19 07:30:25 -07:00
|
|
|
$this->authorize('view', PredefinedKit::class);
|
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
|
|
|
$models = $kit->models;
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2018-10-19 07:30:25 -07:00
|
|
|
return (new PredefinedKitsTransformer)->transformElements($models, $models->count());
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2018-10-19 07:30:25 -07:00
|
|
|
/**
|
2019-02-23 11:44:03 -08:00
|
|
|
* Store the specified resource.
|
2018-10-19 07:30:25 -07:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function storeModel(Request $request, $kit_id)
|
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
2019-03-13 12:15:48 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
2018-10-31 06:06:38 -07:00
|
|
|
|
2018-11-06 08:27:28 -08:00
|
|
|
$model_id = $request->get('model');
|
|
|
|
$quantity = $request->input('quantity', 1);
|
2021-06-10 13:15:52 -07:00
|
|
|
if ($quantity < 1) {
|
2018-11-06 08:27:28 -08:00
|
|
|
$quantity = 1;
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2018-11-06 08:27:28 -08:00
|
|
|
$relation = $kit->models();
|
2021-06-10 13:15:52 -07:00
|
|
|
if ($relation->find($model_id)) {
|
2019-02-19 11:19:00 -08:00
|
|
|
return response()->json(Helper::formatStandardApiResponse('error', null, ['model' => 'Model already attached to kit']));
|
2018-11-06 08:27:28 -08:00
|
|
|
}
|
|
|
|
$relation->attach($model_id, ['quantity' => $quantity]);
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2019-03-13 12:15:48 -07:00
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Model added successfull'));
|
2018-10-19 07:30:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2019-02-27 14:37:58 -08:00
|
|
|
* @param int $kit_id
|
2018-10-19 07:30:25 -07:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function updateModel(Request $request, $kit_id, $model_id)
|
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
|
|
|
$quantity = $request->input('quantity', 1);
|
|
|
|
if ($quantity < 1) {
|
|
|
|
$quantity = 1;
|
|
|
|
}
|
|
|
|
$kit->models()->syncWithoutDetaching([$model_id => ['quantity' => $quantity]]);
|
|
|
|
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'License updated')); // TODO: trans
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-19 07:30:25 -07:00
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $kit_id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2018-11-06 08:27:28 -08:00
|
|
|
public function detachModel($kit_id, $model_id)
|
2018-10-19 07:30:25 -07:00
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
2019-02-27 14:37:58 -08:00
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
2018-10-19 07:30:25 -07:00
|
|
|
|
|
|
|
$kit->models()->detach($model_id);
|
2019-02-19 11:19:00 -08:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, trans('admin/kits/general.model_removed_success')));
|
|
|
|
}
|
2019-02-19 11:19:00 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2019-02-27 14:37:58 -08:00
|
|
|
* @param int $kit_id
|
2019-02-19 11:19:00 -08:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function indexConsumables($kit_id)
|
|
|
|
{
|
2019-02-19 11:19:00 -08:00
|
|
|
$this->authorize('view', PredefinedKit::class);
|
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
|
|
|
$consumables = $kit->consumables;
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2019-02-19 11:19:00 -08:00
|
|
|
return (new PredefinedKitsTransformer)->transformElements($consumables, $consumables->count());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-23 11:44:03 -08:00
|
|
|
* Store the specified resource.
|
2019-02-19 11:19:00 -08:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function storeConsumable(Request $request, $kit_id)
|
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
|
|
|
|
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
|
|
|
$quantity = $request->input('quantity', 1);
|
|
|
|
if ($quantity < 1) {
|
|
|
|
$quantity = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$consumable_id = $request->get('consumable');
|
|
|
|
$relation = $kit->consumables();
|
|
|
|
if ($relation->find($consumable_id)) {
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('error', null, ['consumable' => 'Consumable already attached to kit']));
|
|
|
|
}
|
|
|
|
|
|
|
|
$relation->attach($consumable_id, ['quantity' => $quantity]);
|
|
|
|
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Consumable added successfull')); // TODO: trans
|
2019-02-19 11:19:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2019-02-27 14:37:58 -08:00
|
|
|
* @param int $kit_id
|
2019-02-19 11:19:00 -08:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function updateConsumable(Request $request, $kit_id, $consumable_id)
|
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
|
|
|
$quantity = $request->input('quantity', 1);
|
|
|
|
if ($quantity < 1) {
|
|
|
|
$quantity = 1;
|
|
|
|
}
|
|
|
|
$kit->consumables()->syncWithoutDetaching([$consumable_id => ['quantity' => $quantity]]);
|
|
|
|
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Consumable updated')); // TODO: trans
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-19 11:19:00 -08:00
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $kit_id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function detachConsumable($kit_id, $consumable_id)
|
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
2019-02-27 14:37:58 -08:00
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
2019-02-19 11:19:00 -08:00
|
|
|
|
|
|
|
$kit->consumables()->detach($consumable_id);
|
2021-06-10 13:15:52 -07:00
|
|
|
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Delete was successfull')); // TODO: trans
|
2019-02-19 11:19:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2019-02-27 14:37:58 -08:00
|
|
|
* @param int $kit_id
|
2019-02-19 11:19:00 -08:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function indexAccessories($kit_id)
|
|
|
|
{
|
2019-02-19 11:19:00 -08:00
|
|
|
$this->authorize('view', PredefinedKit::class);
|
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
|
|
|
$accessories = $kit->accessories;
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2019-02-19 11:19:00 -08:00
|
|
|
return (new PredefinedKitsTransformer)->transformElements($accessories, $accessories->count());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-23 11:44:03 -08:00
|
|
|
* Store the specified resource.
|
2019-02-19 11:19:00 -08:00
|
|
|
*
|
2019-02-27 14:37:58 -08:00
|
|
|
* @param int $kit_id
|
2019-02-19 11:19:00 -08:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function storeAccessory(Request $request, $kit_id)
|
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
|
|
|
|
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
|
|
|
$quantity = $request->input('quantity', 1);
|
|
|
|
if ($quantity < 1) {
|
|
|
|
$quantity = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$accessory_id = $request->get('accessory');
|
|
|
|
$relation = $kit->accessories();
|
|
|
|
if ($relation->find($accessory_id)) {
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('error', null, ['accessory' => 'Accessory already attached to kit']));
|
|
|
|
}
|
|
|
|
|
|
|
|
$relation->attach($accessory_id, ['quantity' => $quantity]);
|
|
|
|
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Accessory added successfull')); // TODO: trans
|
2019-02-19 11:19:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2019-02-27 14:37:58 -08:00
|
|
|
* @param int $kit_id
|
2019-02-19 11:19:00 -08:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2021-06-10 13:15:52 -07:00
|
|
|
public function updateAccessory(Request $request, $kit_id, $accessory_id)
|
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
|
|
|
$quantity = $request->input('quantity', 1);
|
|
|
|
if ($quantity < 1) {
|
|
|
|
$quantity = 1;
|
|
|
|
}
|
|
|
|
$kit->accessories()->syncWithoutDetaching([$accessory_id => ['quantity' => $quantity]]);
|
|
|
|
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Accessory updated')); // TODO: trans
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-19 11:19:00 -08:00
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $kit_id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function detachAccessory($kit_id, $accessory_id)
|
|
|
|
{
|
|
|
|
$this->authorize('update', PredefinedKit::class);
|
2019-02-27 14:37:58 -08:00
|
|
|
$kit = PredefinedKit::findOrFail($kit_id);
|
2019-02-19 11:19:00 -08:00
|
|
|
|
|
|
|
$kit->accessories()->detach($accessory_id);
|
2021-06-10 13:15:52 -07:00
|
|
|
|
|
|
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Delete was successfull')); // TODO: trans
|
2019-02-19 11:19:00 -08:00
|
|
|
}
|
2018-10-19 07:30:25 -07:00
|
|
|
}
|