Browse Source

fix(report): fixed delete report for image

pull/1/head
Watiah11 6 months ago
parent
commit
bf3cc0fa79
  1. 15
      app/Http/Controllers/ReportActivityMaterialController.php

15
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);
}

Loading…
Cancel
Save