diff --git a/app/Http/Controllers/ReportActivityMaterialController.php b/app/Http/Controllers/ReportActivityMaterialController.php index 62e08f3..403fdbd 100644 --- a/app/Http/Controllers/ReportActivityMaterialController.php +++ b/app/Http/Controllers/ReportActivityMaterialController.php @@ -8,6 +8,8 @@ use Illuminate\Support\Facades\DB; use App\Models\ReportActivityMaterial; use App\Models\Activity; use App\Models\AssignMaterial; +use App\Models\Company; +use App\Models\Image; use Yajra\Datatables\Datatables; use DateTime; @@ -100,10 +102,19 @@ class ReportActivityMaterialController extends Controller } } - public function delete($id) + public function delete($id, $company_id) { - if(!ReportActivityMaterial::findOrFail($id)->delete()) + $data = ReportActivityMaterial::findOrFail($id); + $company = Company::find($company_id); + $image = Image::where([['ref_id', $id],['category','report_activity']])->first(); + + if($data && $company && $image) { + $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); + unlink($destinationPath['pathImage'].$image['image']); + } + if(!$data->delete()) { return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500); + } return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200); } diff --git a/routes/web.php b/routes/web.php index 840db36..9037b16 100644 --- a/routes/web.php +++ b/routes/web.php @@ -431,7 +431,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro $router->post('/report-activity-material/add', 'ReportActivityMaterialController@add'); $router->post('/report-activity-material/search', 'ReportActivityMaterialController@search'); - $router->delete('/report-activity-material/delete/{id}', 'ReportActivityMaterialController@delete'); + $router->delete('/report-activity-material/delete/{id}/{company_id}', 'ReportActivityMaterialController@delete'); $router->get('/report-activity-material/list', 'ReportActivityMaterialController@list'); $router->get('/report-activity-material/datatables', 'ReportActivityMaterialController@datatables'); $router->post('/report-activity-material/update-status', 'ReportActivityMaterialController@updateStatusStartFinish');