From 4796598bb6967eb569c0290e9c7ba4b9e3b4ae99 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Mon, 14 Aug 2023 14:35:31 -0600 Subject: [PATCH] Add declinedCheckout method to Accessory model --- app/Models/Accessory.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index 7576cc644f..e1da483b97 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -32,6 +32,16 @@ class Accessory extends SnipeModel use Searchable; use Acceptable; + + public function declinedCheckout(User $declinedBy, $signature) + { + if (is_null($accessory_user = \DB::table('accessories_users')->where('assigned_to', $declinedBy->id)->where('accessory_id', $this->id)->latest('created_at'))) { + // Redirect to the accessory management page with error + return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); + } + + $accessory_user->limit(1)->delete(); + } /** * The attributes that should be included when searching the model.