mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Route model binding for resource groups
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
972bd1ef83
commit
f7d213052a
|
@ -95,16 +95,9 @@ class AccessoriesController extends Controller
|
|||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @param int $accessoryId
|
||||
*/
|
||||
public function edit($accessoryId = null) : View | RedirectResponse
|
||||
public function edit(Accessory $accessory) : View | RedirectResponse
|
||||
{
|
||||
|
||||
if ($item = Accessory::find($accessoryId)) {
|
||||
$this->authorize($item);
|
||||
return view('accessories.edit', compact('item'))->with('category_type', 'accessory');
|
||||
}
|
||||
|
||||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
|
||||
|
||||
return view('accessories.edit')->with('category_type', 'accessory');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,19 +107,12 @@ class AccessoriesController extends Controller
|
|||
* @param int $accessoryId
|
||||
* @since [v6.0]
|
||||
*/
|
||||
public function getClone($accessoryId = null) : View | RedirectResponse
|
||||
public function getClone(Accessory $accessory) : View | RedirectResponse
|
||||
{
|
||||
|
||||
$this->authorize('create', Accessory::class);
|
||||
|
||||
// Check if the asset exists
|
||||
if (is_null($accessory_to_clone = Accessory::find($accessoryId))) {
|
||||
// Redirect to the asset management page
|
||||
return redirect()->route('accessories.index')
|
||||
->with('error', trans('admin/accessories/message.does_not_exist', ['id' => $accessoryId]));
|
||||
}
|
||||
|
||||
$accessory = clone $accessory_to_clone;
|
||||
$accessory = clone $accessory;
|
||||
$accessory->id = null;
|
||||
$accessory->location_id = null;
|
||||
|
||||
|
@ -142,9 +128,9 @@ class AccessoriesController extends Controller
|
|||
* @param ImageUploadRequest $request
|
||||
* @param int $accessoryId
|
||||
*/
|
||||
public function update(ImageUploadRequest $request, $accessoryId = null) : RedirectResponse
|
||||
public function update(ImageUploadRequest $request, Accessory $accessory) : RedirectResponse
|
||||
{
|
||||
if ($accessory = Accessory::withCount('checkouts as checkouts_count')->find($accessoryId)) {
|
||||
if ($accessory = Accessory::withCount('checkouts as checkouts_count')->find($accessory->id)) {
|
||||
|
||||
$this->authorize($accessory);
|
||||
|
||||
|
@ -231,14 +217,10 @@ class AccessoriesController extends Controller
|
|||
* @see AccessoriesController::getDataView() method that generates the JSON response
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function show($accessoryID = null) : View | RedirectResponse
|
||||
public function show(Accessory $accessory) : View | RedirectResponse
|
||||
{
|
||||
$accessory = Accessory::withCount('checkouts as checkouts_count')->find($accessoryID);
|
||||
$accessory = Accessory::withCount('checkouts as checkouts_count')->find($accessory->id);
|
||||
$this->authorize('view', $accessory);
|
||||
if (isset($accessory->id)) {
|
||||
return view('accessories.view', compact('accessory'));
|
||||
}
|
||||
|
||||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist', ['id' => $accessoryID]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,16 +109,11 @@ class AssetModelsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @param int $modelId
|
||||
*/
|
||||
public function edit($modelId = null) : View | RedirectResponse
|
||||
public function edit(AssetModel $model) : View | RedirectResponse
|
||||
{
|
||||
$this->authorize('update', AssetModel::class);
|
||||
if ($item = AssetModel::find($modelId)) {
|
||||
$category_type = 'asset';
|
||||
return view('models/edit', compact('item', 'category_type'))->with('depreciation_list', Helper::depreciationList());
|
||||
|
||||
}
|
||||
|
||||
return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist'));
|
||||
return view('models/edit', compact('category_type'))->with('item', $model)->with('depreciation_list', Helper::depreciationList());
|
||||
}
|
||||
|
||||
|
||||
|
@ -133,16 +128,11 @@ class AssetModelsController extends Controller
|
|||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(StoreAssetModelRequest $request, $modelId) : RedirectResponse
|
||||
public function update(StoreAssetModelRequest $request, AssetModel $model) : RedirectResponse
|
||||
{
|
||||
$this->authorize('update', AssetModel::class);
|
||||
|
||||
if (is_null($model = AssetModel::find($modelId))) {
|
||||
return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist'));
|
||||
}
|
||||
|
||||
$model = $request->handleImages($model);
|
||||
|
||||
$model->depreciation_id = $request->input('depreciation_id');
|
||||
$model->eol = $request->input('eol');
|
||||
$model->name = $request->input('name');
|
||||
|
@ -267,18 +257,12 @@ class AssetModelsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @param int $modelId
|
||||
*/
|
||||
public function show($modelId = null) : View | RedirectResponse
|
||||
public function show(AssetModel $model) : View | RedirectResponse
|
||||
{
|
||||
$this->authorize('view', AssetModel::class);
|
||||
$model = AssetModel::withTrashed()->find($modelId);
|
||||
|
||||
if (isset($model->id)) {
|
||||
return view('models/view', compact('model'));
|
||||
}
|
||||
|
||||
return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the clone page to clone a model
|
||||
*
|
||||
|
|
|
@ -201,7 +201,7 @@ class AssetsController extends Controller
|
|||
$asset->checkOut($target, auth()->user(), date('Y-m-d H:i:s'), $request->input('expected_checkin', null), 'Checked out on asset creation', $request->get('name'), $location);
|
||||
}
|
||||
|
||||
$successes[] = "<a href='" . route('hardware.show', ['hardware' => $asset->id]) . "' style='color: white;'>" . e($asset->asset_tag) . "</a>";
|
||||
$successes[] = "<a href='" . route('hardware.show', $asset) . "' style='color: white;'>" . e($asset->asset_tag) . "</a>";
|
||||
|
||||
} else {
|
||||
$failures[] = join(",", $asset->getErrors()->all());
|
||||
|
@ -222,7 +222,7 @@ class AssetsController extends Controller
|
|||
//the most common case, keeping it so we don't have to make every use of that translation string be trans_choice'ed
|
||||
//and re-translated
|
||||
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
|
||||
->with('success-unescaped', trans('admin/hardware/message.create.success_linked', ['link' => route('hardware.show', ['hardware' => $asset->id]), 'id', 'tag' => e($asset->asset_tag)]));
|
||||
->with('success-unescaped', trans('admin/hardware/message.create.success_linked', ['link' => route('hardware.show', $asset), 'id', 'tag' => e($asset->asset_tag)]));
|
||||
} else {
|
||||
//multi-success
|
||||
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
|
||||
|
@ -240,15 +240,13 @@ class AssetsController extends Controller
|
|||
* Returns a view that presents a form to edit an existing asset.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @param int $assetId
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit(Asset $asset) : View | RedirectResponse
|
||||
{
|
||||
$this->authorize($asset);
|
||||
|
||||
return view('hardware/edit', compact('asset'))
|
||||
return view('hardware/edit')
|
||||
->with('statuslabel_list', Helper::statusLabelList())
|
||||
->with('statuslabel_types', Helper::statusTypeList());
|
||||
}
|
||||
|
@ -285,7 +283,7 @@ class AssetsController extends Controller
|
|||
|
||||
$qr_code = (object) [
|
||||
'display' => $settings->qr_code == '1',
|
||||
//'url' => route('qr_code/hardware', ['asset' => $asset]),
|
||||
'url' => route('qr_code/hardware', $asset),
|
||||
];
|
||||
|
||||
return view('hardware/view', compact('asset', 'qr_code', 'settings'))
|
||||
|
@ -302,14 +300,9 @@ class AssetsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
*/
|
||||
public function update(ImageUploadRequest $request, $assetId = null) : RedirectResponse
|
||||
public function update(ImageUploadRequest $request, Asset $asset) : RedirectResponse
|
||||
{
|
||||
|
||||
// Check if the asset exists
|
||||
if (! $asset = Asset::find($assetId)) {
|
||||
// Redirect to the asset management page with error
|
||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
||||
}
|
||||
$this->authorize($asset);
|
||||
|
||||
$asset->status_id = $request->input('status_id', null);
|
||||
|
@ -424,7 +417,7 @@ class AssetsController extends Controller
|
|||
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
|
||||
|
||||
if ($asset->save()) {
|
||||
return redirect()->to(Helper::getRedirectOption($request, $assetId, 'Assets'))
|
||||
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
|
||||
->with('success', trans('admin/hardware/message.update.success'));
|
||||
}
|
||||
|
||||
|
|
|
@ -80,16 +80,10 @@ final class CompaniesController extends Controller
|
|||
* @since [v1.8]
|
||||
* @param int $companyId
|
||||
*/
|
||||
public function edit($companyId) : View | RedirectResponse
|
||||
public function edit(Company $company) : View | RedirectResponse
|
||||
{
|
||||
if (is_null($item = Company::find($companyId))) {
|
||||
return redirect()->route('companies.index')
|
||||
->with('error', trans('admin/companies/message.does_not_exist'));
|
||||
}
|
||||
|
||||
$this->authorize('update', $item);
|
||||
|
||||
return view('companies/edit')->with('item', $item);
|
||||
$this->authorize('update', $company);
|
||||
return view('companies/edit');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,14 +94,10 @@ final class CompaniesController extends Controller
|
|||
* @param ImageUploadRequest $request
|
||||
* @param int $companyId
|
||||
*/
|
||||
public function update(ImageUploadRequest $request, $companyId) : RedirectResponse
|
||||
public function update(ImageUploadRequest $request, Company $company) : RedirectResponse
|
||||
{
|
||||
if (is_null($company = Company::find($companyId))) {
|
||||
return redirect()->route('companies.index')->with('error', trans('admin/companies/message.does_not_exist'));
|
||||
}
|
||||
|
||||
$this->authorize('update', $company);
|
||||
|
||||
$company->name = $request->input('name');
|
||||
$company->phone = $request->input('phone');
|
||||
$company->fax = $request->input('fax');
|
||||
|
@ -158,15 +148,9 @@ final class CompaniesController extends Controller
|
|||
->with('success', trans('admin/companies/message.delete.success'));
|
||||
}
|
||||
|
||||
public function show($id) : View | RedirectResponse
|
||||
public function show(Company $company) : View | RedirectResponse
|
||||
{
|
||||
$this->authorize('view', Company::class);
|
||||
|
||||
if (is_null($company = Company::find($id))) {
|
||||
return redirect()->route('companies.index')
|
||||
->with('error', trans('admin/companies/message.not_found'));
|
||||
}
|
||||
|
||||
return view('companies/view')->with('company', $company);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,15 +107,11 @@ class ComponentsController extends Controller
|
|||
* @return \Illuminate\Contracts\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function edit($componentId = null)
|
||||
public function edit(Component $component)
|
||||
{
|
||||
if ($item = Component::find($componentId)) {
|
||||
$this->authorize('update', $item);
|
||||
|
||||
return view('components/edit', compact('item'))->with('category_type', 'component');
|
||||
}
|
||||
|
||||
return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist'));
|
||||
$this->authorize('update', $component);
|
||||
return view('components/edit')->with('category_type', 'component');
|
||||
}
|
||||
|
||||
|
||||
|
@ -130,11 +126,8 @@ class ComponentsController extends Controller
|
|||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @since [v3.0]
|
||||
*/
|
||||
public function update(ImageUploadRequest $request, $componentId = null)
|
||||
public function update(ImageUploadRequest $request, Component $component)
|
||||
{
|
||||
if (is_null($component = Component::find($componentId))) {
|
||||
return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist'));
|
||||
}
|
||||
$min = $component->numCheckedOut();
|
||||
$validator = Validator::make($request->all(), [
|
||||
'qty' => "required|numeric|min:$min",
|
||||
|
@ -216,17 +209,9 @@ class ComponentsController extends Controller
|
|||
* @return \Illuminate\Contracts\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function show($componentId = null)
|
||||
public function show(Component $component)
|
||||
{
|
||||
$component = Component::find($componentId);
|
||||
|
||||
if (isset($component->id)) {
|
||||
$this->authorize('view', $component);
|
||||
|
||||
return view('components/view', compact('component'));
|
||||
}
|
||||
// Redirect to the user management page
|
||||
return redirect()->route('components.index')
|
||||
->with('error', trans('admin/components/message.does_not_exist'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,15 +104,11 @@ class ConsumablesController extends Controller
|
|||
* @see ConsumablesController::postEdit() method that stores the form data.
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function edit($consumableId = null) : View | RedirectResponse
|
||||
public function edit(Consumable $consumable) : View | RedirectResponse
|
||||
{
|
||||
if ($item = Consumable::find($consumableId)) {
|
||||
$this->authorize($item);
|
||||
$this->authorize($consumable);
|
||||
return view('consumables/edit')->with('category_type', 'consumable');
|
||||
|
||||
return view('consumables/edit', compact('item'))->with('category_type', 'consumable');
|
||||
}
|
||||
|
||||
return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.does_not_exist'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,11 +122,8 @@ class ConsumablesController extends Controller
|
|||
* @see ConsumablesController::getEdit() method that stores the form data.
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function update(StoreConsumableRequest $request, $consumableId = null)
|
||||
public function update(StoreConsumableRequest $request, Consumable $consumable)
|
||||
{
|
||||
if (is_null($consumable = Consumable::find($consumableId))) {
|
||||
return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.does_not_exist'));
|
||||
}
|
||||
|
||||
$min = $consumable->numCheckedOut();
|
||||
$validator = Validator::make($request->all(), [
|
||||
|
@ -202,16 +195,11 @@ class ConsumablesController extends Controller
|
|||
* @return \Illuminate\Contracts\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function show($consumableId = null)
|
||||
public function show(Consumable $consumable)
|
||||
{
|
||||
$consumable = Consumable::withCount('users as users_consumables')->find($consumableId);
|
||||
$consumable = Consumable::withCount('users as users_consumables')->find($consumable->id);
|
||||
$this->authorize($consumable);
|
||||
if (isset($consumable->id)) {
|
||||
return view('consumables/view', compact('consumable'));
|
||||
}
|
||||
|
||||
return redirect()->route('consumables.index')
|
||||
->with('error', trans('admin/consumables/message.does_not_exist'));
|
||||
return view('consumables/view');
|
||||
}
|
||||
|
||||
public function clone(Consumable $consumable) : View
|
||||
|
|
|
@ -73,19 +73,12 @@ class DepartmentsController extends Controller
|
|||
* @param int $id
|
||||
* @since [v4.0]
|
||||
*/
|
||||
public function show($id) : View | RedirectResponse
|
||||
public function show(Department $department) : View | RedirectResponse
|
||||
{
|
||||
$department = Department::find($id);
|
||||
|
||||
$this->authorize('view', $department);
|
||||
|
||||
if (isset($department->id)) {
|
||||
return view('departments/view', compact('department'));
|
||||
}
|
||||
|
||||
return redirect()->route('departments.index')->with('error', trans('admin/departments/message.does_not_exist'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a form view used to create a new department.
|
||||
*
|
||||
|
@ -139,15 +132,10 @@ class DepartmentsController extends Controller
|
|||
* @param int $departmentId
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function edit($departmentId = null) : View | RedirectResponse
|
||||
public function edit(Department $department) : View | RedirectResponse
|
||||
{
|
||||
if (is_null($item = Department::find($departmentId))) {
|
||||
return redirect()->back()->with('error', trans('admin/locations/message.does_not_exist'));
|
||||
}
|
||||
|
||||
$this->authorize('update', $item);
|
||||
|
||||
return view('departments/edit', compact('item'));
|
||||
$this->authorize('update', $department);
|
||||
return view('departments/edit')->with('item', $department);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,11 +146,8 @@ class DepartmentsController extends Controller
|
|||
* @param int $departmentId
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function update(ImageUploadRequest $request, $id) : RedirectResponse
|
||||
public function update(ImageUploadRequest $request, Department $department) : RedirectResponse
|
||||
{
|
||||
if (is_null($department = Department::find($id))) {
|
||||
return redirect()->route('departments.index')->with('error', trans('admin/departments/message.does_not_exist'));
|
||||
}
|
||||
|
||||
$this->authorize('update', $department);
|
||||
|
||||
|
|
|
@ -95,17 +95,11 @@ class DepreciationsController extends Controller
|
|||
* @param int $depreciationId
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function edit($depreciationId = null) : RedirectResponse | View
|
||||
public function edit(Depreciation $depreciation) : RedirectResponse | View
|
||||
{
|
||||
// Check if the depreciation exists
|
||||
if (is_null($item = Depreciation::find($depreciationId))) {
|
||||
// Redirect to the blogs management page
|
||||
return redirect()->route('depreciations.index')->with('error', trans('admin/depreciations/message.does_not_exist'));
|
||||
}
|
||||
|
||||
$this->authorize('update', $item);
|
||||
|
||||
return view('depreciations/edit', compact('item'));
|
||||
$this->authorize('update', $depreciation);
|
||||
return view('depreciations/edit');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,17 +111,10 @@ class DepreciationsController extends Controller
|
|||
* @param int $depreciationId
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function update(Request $request, $depreciationId = null) : RedirectResponse
|
||||
public function update(Request $request, Depreciation $depreciation) : RedirectResponse
|
||||
{
|
||||
// Check if the depreciation exists
|
||||
if (is_null($depreciation = Depreciation::find($depreciationId))) {
|
||||
// Redirect to the blogs management page
|
||||
return redirect()->route('depreciations.index')->with('error', trans('admin/depreciations/message.does_not_exist'));
|
||||
}
|
||||
|
||||
$this->authorize('update', $depreciation);
|
||||
|
||||
// Depreciation data
|
||||
$depreciation->name = $request->input('name');
|
||||
$depreciation->months = $request->input('months');
|
||||
|
||||
|
@ -191,12 +178,12 @@ class DepreciationsController extends Controller
|
|||
* @param int $depreciationId
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function show($id) : View | RedirectResponse
|
||||
public function show(Depreciation $depreciation) : View | RedirectResponse
|
||||
{
|
||||
$depreciation = Depreciation::withCount('assets as assets_count')
|
||||
->withCount('models as models_count')
|
||||
->withCount('licenses as licenses_count')
|
||||
->find($id);
|
||||
->find($depreciation->id);
|
||||
|
||||
$this->authorize('view', $depreciation);
|
||||
|
||||
|
|
|
@ -121,13 +121,10 @@ class LicensesController extends Controller
|
|||
* @return \Illuminate\Contracts\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function edit($licenseId = null)
|
||||
public function edit(License $license)
|
||||
{
|
||||
if (is_null($item = License::find($licenseId))) {
|
||||
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist'));
|
||||
}
|
||||
|
||||
$this->authorize('update', $item);
|
||||
$this->authorize('update', $license);
|
||||
|
||||
$maintained_list = [
|
||||
'' => 'Maintained',
|
||||
|
@ -135,7 +132,7 @@ class LicensesController extends Controller
|
|||
'0' => 'No',
|
||||
];
|
||||
|
||||
return view('licenses/edit', compact('item'))
|
||||
return view('licenses/edit')
|
||||
->with('depreciation_list', Helper::depreciationList())
|
||||
->with('maintained_list', $maintained_list);
|
||||
}
|
||||
|
@ -153,11 +150,9 @@ class LicensesController extends Controller
|
|||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(Request $request, $licenseId = null)
|
||||
public function update(Request $request, License $license)
|
||||
{
|
||||
if (is_null($license = License::find($licenseId))) {
|
||||
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist'));
|
||||
}
|
||||
|
||||
|
||||
$this->authorize('update', $license);
|
||||
|
||||
|
@ -201,10 +196,10 @@ class LicensesController extends Controller
|
|||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function destroy($licenseId)
|
||||
public function destroy(License $license)
|
||||
{
|
||||
// Check if the license exists
|
||||
if (is_null($license = License::find($licenseId))) {
|
||||
if (is_null($license = License::find($license->id))) {
|
||||
// Redirect to the license management page
|
||||
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
||||
}
|
||||
|
@ -238,14 +233,9 @@ class LicensesController extends Controller
|
|||
* @return \Illuminate\Contracts\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function show($licenseId = null)
|
||||
public function show(License $license)
|
||||
{
|
||||
$license = License::with('assignedusers')->find($licenseId);
|
||||
|
||||
if (!$license) {
|
||||
return redirect()->route('licenses.index')
|
||||
->with('error', trans('admin/licenses/message.does_not_exist'));
|
||||
}
|
||||
$license = License::with('assignedusers')->find($license->id);
|
||||
|
||||
$users_count = User::where('autoassign_licenses', '1')->count();
|
||||
$total_seats_count = $license->totalSeatsByLicenseID();
|
||||
|
@ -267,10 +257,10 @@ class LicensesController extends Controller
|
|||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @param int $licenseId
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @return \Illuminate\Http\RedirectResponse | \Illuminate\Contracts\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function getClone($licenseId = null)
|
||||
public function getClone($licenseId = null) : \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
if (is_null($license_to_clone = License::find($licenseId))) {
|
||||
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist'));
|
||||
|
|
|
@ -97,15 +97,10 @@ class LocationsController extends Controller
|
|||
* @param int $locationId
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function edit($locationId = null) : View | RedirectResponse
|
||||
public function edit(Location $location) : View | RedirectResponse
|
||||
{
|
||||
$this->authorize('update', Location::class);
|
||||
// Check if the location exists
|
||||
if (is_null($item = Location::find($locationId))) {
|
||||
return redirect()->route('locations.index')->with('error', trans('admin/locations/message.does_not_exist'));
|
||||
}
|
||||
|
||||
return view('locations/edit', compact('item'));
|
||||
return view('locations/edit');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,15 +112,10 @@ class LocationsController extends Controller
|
|||
* @param int $locationId
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function update(ImageUploadRequest $request, $locationId = null) : RedirectResponse
|
||||
public function update(ImageUploadRequest $request, Location $location) : RedirectResponse
|
||||
{
|
||||
$this->authorize('update', Location::class);
|
||||
// Check if the location exists
|
||||
if (is_null($location = Location::find($locationId))) {
|
||||
return redirect()->route('locations.index')->with('error', trans('admin/locations/message.does_not_exist'));
|
||||
}
|
||||
|
||||
// Update the location data
|
||||
$location->name = $request->input('name');
|
||||
$location->parent_id = $request->input('parent_id', null);
|
||||
$location->currency = $request->input('currency', '$');
|
||||
|
@ -194,7 +184,7 @@ class LocationsController extends Controller
|
|||
* @param int $id
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function show($id = null) : View | RedirectResponse
|
||||
public function show(Location $location) : View | RedirectResponse
|
||||
{
|
||||
$location = Location::withCount('assignedAssets as assigned_assets_count')
|
||||
->withCount('assets as assets_count')
|
||||
|
@ -202,7 +192,7 @@ class LocationsController extends Controller
|
|||
->withCount('children as children_count')
|
||||
->withCount('users as users_count')
|
||||
->withTrashed()
|
||||
->find($id);
|
||||
->find($location->id);
|
||||
|
||||
if (isset($location->id)) {
|
||||
return view('locations/view', compact('location'));
|
||||
|
|
|
@ -85,18 +85,10 @@ class ManufacturersController extends Controller
|
|||
* @param int $manufacturerId
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function edit($manufacturerId = null) : View | RedirectResponse
|
||||
public function edit(Manufacturer $manufacturer) : View | RedirectResponse
|
||||
{
|
||||
// Handles manufacturer checks and permissions.
|
||||
$this->authorize('update', Manufacturer::class);
|
||||
|
||||
// Check if the manufacturer exists
|
||||
if (! $item = Manufacturer::find($manufacturerId)) {
|
||||
return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.does_not_exist'));
|
||||
}
|
||||
|
||||
// Show the page
|
||||
return view('manufacturers/edit', compact('item'));
|
||||
return view('manufacturers/edit');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,16 +100,10 @@ class ManufacturersController extends Controller
|
|||
* @param int $manufacturerId
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function update(ImageUploadRequest $request, $manufacturerId = null) : RedirectResponse
|
||||
public function update(ImageUploadRequest $request, Manufacturer $manufacturer) : RedirectResponse
|
||||
{
|
||||
$this->authorize('update', Manufacturer::class);
|
||||
// Check if the manufacturer exists
|
||||
if (is_null($manufacturer = Manufacturer::find($manufacturerId))) {
|
||||
// Redirect to the manufacturer page
|
||||
return redirect()->route('manufacturers.index')->with('error', trans('admin/manufacturers/message.does_not_exist'));
|
||||
}
|
||||
|
||||
// Save the data
|
||||
$manufacturer->name = $request->input('name');
|
||||
$manufacturer->url = $request->input('url');
|
||||
$manufacturer->support_url = $request->input('support_url');
|
||||
|
@ -185,20 +171,12 @@ class ManufacturersController extends Controller
|
|||
* @param int $manufacturerId
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function show($manufacturerId = null) : View | RedirectResponse
|
||||
public function show(Manufacturer $manufacturer) : View | RedirectResponse
|
||||
{
|
||||
$this->authorize('view', Manufacturer::class);
|
||||
$manufacturer = Manufacturer::find($manufacturerId);
|
||||
|
||||
if (isset($manufacturer->id)) {
|
||||
return view('manufacturers/view', compact('manufacturer'));
|
||||
}
|
||||
|
||||
$error = trans('admin/manufacturers/message.does_not_exist');
|
||||
// Redirect to the user management page
|
||||
return redirect()->route('manufacturers.index')->with('error', $error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore a given Manufacturer (mark as un-deleted)
|
||||
*
|
||||
|
|
|
@ -91,20 +91,13 @@ class StatuslabelsController extends Controller
|
|||
*
|
||||
* @param int $statuslabelId
|
||||
*/
|
||||
public function edit($statuslabelId = null) : View | RedirectResponse
|
||||
public function edit(Statuslabel $statuslabel) : View | RedirectResponse
|
||||
{
|
||||
$this->authorize('update', Statuslabel::class);
|
||||
// Check if the Statuslabel exists
|
||||
if (is_null($item = Statuslabel::find($statuslabelId))) {
|
||||
// Redirect to the blogs management page
|
||||
return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.does_not_exist'));
|
||||
}
|
||||
|
||||
$use_statuslabel_type = $item->getStatuslabelType();
|
||||
|
||||
$statuslabel_types = ['' => trans('admin/hardware/form.select_statustype')] + ['undeployable' => trans('admin/hardware/general.undeployable')] + ['pending' => trans('admin/hardware/general.pending')] + ['archived' => trans('admin/hardware/general.archived')] + ['deployable' => trans('admin/hardware/general.deployable')];
|
||||
|
||||
return view('statuslabels/edit', compact('item', 'statuslabel_types'))->with('use_statuslabel_type', $use_statuslabel_type);
|
||||
return view('statuslabels/edit', compact('statuslabel_types'))->with('use_statuslabel_type', $statuslabel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,14 +105,9 @@ class StatuslabelsController extends Controller
|
|||
*
|
||||
* @param int $statuslabelId
|
||||
*/
|
||||
public function update(Request $request, $statuslabelId = null) : RedirectResponse
|
||||
public function update(Request $request, Statuslabel $statuslabel) : RedirectResponse
|
||||
{
|
||||
$this->authorize('update', Statuslabel::class);
|
||||
// Check if the Statuslabel exists
|
||||
if (is_null($statuslabel = Statuslabel::find($statuslabelId))) {
|
||||
// Redirect to the blogs management page
|
||||
return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.does_not_exist'));
|
||||
}
|
||||
|
||||
if (! $request->filled('statuslabel_types')) {
|
||||
return redirect()->back()->withInput()->withErrors(['statuslabel_types' => trans('validation.statuslabel_type')]);
|
||||
|
|
|
@ -77,17 +77,10 @@ class SuppliersController extends Controller
|
|||
*
|
||||
* @param int $supplierId
|
||||
*/
|
||||
public function edit($supplierId = null) : View | RedirectResponse
|
||||
public function edit(Supplier $supplier) : View | RedirectResponse
|
||||
{
|
||||
$this->authorize('update', Supplier::class);
|
||||
// Check if the supplier exists
|
||||
if (is_null($item = Supplier::find($supplierId))) {
|
||||
// Redirect to the supplier page
|
||||
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.does_not_exist'));
|
||||
}
|
||||
|
||||
// Show the page
|
||||
return view('suppliers/edit', compact('item'));
|
||||
return view('suppliers/edit');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,14 +88,9 @@ class SuppliersController extends Controller
|
|||
*
|
||||
* @param int $supplierId
|
||||
*/
|
||||
public function update($supplierId, ImageUploadRequest $request) : RedirectResponse
|
||||
public function update(ImageUploadRequest $request, Supplier $supplier) : RedirectResponse
|
||||
{
|
||||
$this->authorize('update', Supplier::class);
|
||||
|
||||
if (is_null($supplier = Supplier::find($supplierId))) {
|
||||
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.does_not_exist'));
|
||||
}
|
||||
|
||||
// Save the data
|
||||
$supplier->name = request('name');
|
||||
$supplier->address = request('address');
|
||||
|
@ -163,15 +151,10 @@ class SuppliersController extends Controller
|
|||
* @param null $supplierId
|
||||
* @internal param int $assetId
|
||||
*/
|
||||
public function show($supplierId = null) : View | RedirectResponse
|
||||
public function show(Supplier $supplier) : View | RedirectResponse
|
||||
{
|
||||
$this->authorize('view', Supplier::class);
|
||||
$supplier = Supplier::find($supplierId);
|
||||
|
||||
if (isset($supplier->id)) {
|
||||
return view('suppliers/view', compact('supplier'));
|
||||
}
|
||||
|
||||
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.does_not_exist'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,11 +182,11 @@ class UsersController extends Controller
|
|||
* @internal param int $id
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit(User $user)
|
||||
{
|
||||
|
||||
$this->authorize('update', User::class);
|
||||
$user = User::with(['assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc'])->withTrashed()->find($id);
|
||||
$user = User::with(['assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc'])->withTrashed()->find($user->id);
|
||||
|
||||
if ($user) {
|
||||
|
||||
|
@ -198,7 +198,7 @@ class UsersController extends Controller
|
|||
$userPermissions = Helper::selectedPermissionsArray($permissions, $user->permissions);
|
||||
$permissions = $this->filterDisplayable($permissions);
|
||||
|
||||
return view('users/edit', compact('user', 'groups', 'userGroups', 'permissions', 'userPermissions'))->with('item', $user);
|
||||
return view('users/edit', compact('user', 'groups', 'userGroups', 'permissions', 'userPermissions'));
|
||||
}
|
||||
|
||||
return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', compact('id')));
|
||||
|
@ -324,11 +324,11 @@ class UsersController extends Controller
|
|||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function destroy(DeleteUserRequest $request, $id = null)
|
||||
public function destroy(DeleteUserRequest $request, User $user)
|
||||
{
|
||||
$this->authorize('delete', User::class);
|
||||
|
||||
if ($user = User::find($id)) {
|
||||
if ($user = User::find($user->id)) {
|
||||
|
||||
$this->authorize('delete', $user);
|
||||
|
||||
|
@ -398,25 +398,20 @@ class UsersController extends Controller
|
|||
* @return \Illuminate\Contracts\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function show($userId = null)
|
||||
public function show(User $user)
|
||||
{
|
||||
// Make sure the user can view users at all
|
||||
$this->authorize('view', User::class);
|
||||
|
||||
$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($userId);
|
||||
$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($user->id);
|
||||
|
||||
// Make sure they can view this particular user
|
||||
$this->authorize('view', $user);
|
||||
|
||||
if ($user) {
|
||||
$userlog = $user->userlog->load('item');
|
||||
return view('users/view', compact('user', 'userlog'))->with('settings', Setting::getSettings());
|
||||
}
|
||||
|
||||
return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', ['id' => $userId]));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a view containing a pre-populated new user form,
|
||||
|
@ -428,7 +423,7 @@ class UsersController extends Controller
|
|||
* @return \Illuminate\Contracts\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function getClone(Request $request, $id = null)
|
||||
public function getClone(Request $request, User $user)
|
||||
{
|
||||
$this->authorize('create', User::class);
|
||||
|
||||
|
@ -438,7 +433,7 @@ class UsersController extends Controller
|
|||
app('request')->request->set('permissions', $permissions);
|
||||
|
||||
|
||||
$user_to_clone = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($id);
|
||||
$user_to_clone = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($user->id);
|
||||
// Make sure they can view this particular user
|
||||
$this->authorize('view', $user_to_clone);
|
||||
|
||||
|
|
Loading…
Reference in a new issue