From 835985b9b77fa1bb438ad550abd43512162e90e4 Mon Sep 17 00:00:00 2001 From: didier Date: Sun, 10 Nov 2024 17:21:19 +0100 Subject: [PATCH] add delete action --- app/Http/Controllers/ActionplanController.php | 25 +++++++++++++++++++ resources/views/actions/show.blade.php | 17 +++++++++---- routes/web.php | 1 + 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ActionplanController.php b/app/Http/Controllers/ActionplanController.php index 7c04293..7318581 100644 --- a/app/Http/Controllers/ActionplanController.php +++ b/app/Http/Controllers/ActionplanController.php @@ -489,4 +489,29 @@ public function export() ); } + public function delete() { + // For administrators and users only + abort_if( + Auth::User()->role !== 1 && Auth::User()->rol !== 2, + Response::HTTP_FORBIDDEN, + '403 Forbidden' + ); + + // Get the action plan + $id = (int)request('id'); + $action = Action::find($id); + + // Action not found + abort_if($action === null, Response::HTTP_NOT_FOUND, '404 Not Found'); + + // delete links + DB::table('action_measure')->where('action_id', $action->id)->delete(); + + // delete + $action->delete(); + + // Return + return redirect('/actions'); + } + } diff --git a/resources/views/actions/show.blade.php b/resources/views/actions/show.blade.php index 40e7608..2258896 100644 --- a/resources/views/actions/show.blade.php +++ b/resources/views/actions/show.blade.php @@ -172,19 +172,26 @@ {{ trans('common.save') }}   - +   {{ trans("common.close") }}   @endif - - -   - {{ trans("common.edit") }} + + +   + {{ trans('common.edit') }}   + +     diff --git a/routes/web.php b/routes/web.php index bd4a7d1..fd182a7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -108,6 +108,7 @@ Route::post('/action/update', 'ActionplanController@update'); Route::post('/action/save', 'ActionplanController@save'); Route::post('/action/close', 'ActionplanController@doClose'); + Route::post('/action/delete', 'ActionplanController@delete'); /* Reports */ Route::get('/reports', 'ReportController@show');