Browse Source

update condition upload

pull/1/head
wahyun 9 months ago
parent
commit
3d7d02e246
  1. 25
      app/Http/Controllers/ImageController.php

25
app/Http/Controllers/ImageController.php

@ -6,11 +6,13 @@ use App\Models\Image;
use App\Models\Company;
use Illuminate\Http\Request;
use App\Models\ProductTransaction;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class ImageController extends Controller
{
public function uploadImage(Request $request){
DB::beginTransaction();
if($request->hasFile('files')){
$this->validate($request, [
@ -27,9 +29,13 @@ class ImageController extends Controller
$company = Company::where('company_name', $request->company_name)->first();
if($company) {
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$getLimitStorage = $this->setLimitsStorage($company, $dokumen, $name, $destinationPath['pathImage'], $destinationPath);
$getLimitStorage = $this->setLimitsStorage($company, $dokumen, $destinationPath['pathImage'], $destinationPath);
}
if(isset($getLimitStorage)) {
if($getLimitStorage === false) {
DB::rollBack();
return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500);
}
if(isset($getLimitStorage) && $getLimitStorage['resultMove']) {
$data = [
'ref_id' => (int)$ref_id,
'image' => $name,
@ -63,18 +69,21 @@ class ImageController extends Controller
'favicon_image' => array('content' => $name)
]);
}
if($result){
if($dokumen->move($destinationPath['pathImage'], $name) && $result) {
DB::commit();
return response()->json(['status' => 'success', "name_image" => $name,'message' => 'image upload is successfully!','code' => 200], 200);
} else {
DB::rollBack();
unlink($destinationPath['pathImage'].$name);
return response()->json(['status'=>'failed','message'=>'image upload is failed!','code'=>400], 400);
return response()->json(['status' => 'failed','message' => 'image upload is failed! pertama' ,'code' => 400], 400);
}
} else {
return response()->json(['status'=>'failed','message'=>'image upload is failed!','code'=>400], 400);
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'image upload is failed! kedua','code'=>400], 400);
}
} else {
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'image is required!','code'=>400], 400);
}
}
@ -210,7 +219,7 @@ class ImageController extends Controller
public function deleteByRef($id, $category, $company_id)
{
$data = Image::where("ref_id", intval($id))->where("category", $category)->first();
$data = Image::where("ref_id", (int)$id)->where("category", $category)->first();
$company = Company::find($company_id);
if($data && $company){
$destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);

Loading…
Cancel
Save