From 08f4fe5f35376183b412c85d807ac8f6c52aa3f5 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 25 Jul 2024 22:02:34 +0100 Subject: [PATCH] Add status messages to redirect Signed-off-by: snipe --- app/Http/Controllers/Assets/AssetCheckinController.php | 8 +++----- app/Http/Controllers/Assets/AssetCheckoutController.php | 5 +++-- app/Http/Controllers/Assets/AssetsController.php | 8 +++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.php index 4794fa0411..f84a468a60 100644 --- a/app/Http/Controllers/Assets/AssetCheckinController.php +++ b/app/Http/Controllers/Assets/AssetCheckinController.php @@ -11,7 +11,6 @@ use App\Models\Asset; use App\Models\CheckoutAcceptance; use App\Models\LicenseSeat; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Log; use \Illuminate\Contracts\View\View; use \Illuminate\Http\RedirectResponse; @@ -83,7 +82,6 @@ class AssetCheckinController extends Controller } $asset->expected_checkin = null; - //$asset->last_checkout = null; $asset->last_checkin = now(); $asset->assignedTo()->disassociate($asset); $asset->accepted = null; @@ -128,12 +126,12 @@ class AssetCheckinController extends Controller $acceptance->delete(); }); - Session::put('redirect_option', $request->get('redirect_option')); - // Was the asset updated? + session()->put('redirect_option', $request->get('redirect_option')); + if ($asset->save()) { event(new CheckoutableCheckedIn($asset, $target, auth()->user(), $request->input('note'), $checkin_at, $originalValues)); - return Helper::getRedirectOption($asset, $assetId, 'Assets'); + return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))->with('success', trans('admin/hardware/message.checkin.success')); } // Redirect to the asset management page with error return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.error').$asset->getErrors()); diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php index 355f9387bb..05b766916b 100644 --- a/app/Http/Controllers/Assets/AssetCheckoutController.php +++ b/app/Http/Controllers/Assets/AssetCheckoutController.php @@ -109,10 +109,11 @@ class AssetCheckoutController extends Controller } } - Session::put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]); + session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]); if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, $request->get('note'), $request->get('name'))) { - return Helper::getRedirectOption($request, $assetId, 'Assets'); + return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets')) + ->with('success', trans('admin/hardware/message.checkout.success')); } // Redirect to the asset management page with error return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error').$asset->getErrors()); diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index c418866b33..a55afdc14e 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -207,8 +207,10 @@ class AssetsController extends Controller session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]); + if ($success) { - return redirect()->route('hardware.index') + + 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)])); @@ -293,7 +295,6 @@ class AssetsController extends Controller public function update(ImageUploadRequest $request, $assetId = null) : RedirectResponse { - // Check if the asset exists if (! $asset = Asset::find($assetId)) { // Redirect to the asset management page with error @@ -395,7 +396,8 @@ class AssetsController extends Controller session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]); if ($asset->save()) { - return Helper::getRedirectOption($request, $assetId, 'Assets'); + return redirect()->to(Helper::getRedirectOption($request, $assetId, 'Assets')) + ->with('success', trans('admin/hardware/message.update.success')); } return redirect()->back()->withInput()->withErrors($asset->getErrors());