TestResultController-UpdateImages

This commit is contained in:
Fayyazi
2019-07-21 10:01:22 +04:30
parent eb83d7e253
commit 3ba9a3f7f1
+11 -16
View File
@@ -265,14 +265,6 @@ class TestResultController extends Controller
return $path;
}
public function hasFile($key)
{
if (is_array($file = $this->file($key))) $file = head($file);
return $file instanceof \SplFileInfo;
}
public function update(StoreTestResultRequest $request, TestResult $TestResult)
{
$TestResultData = [
@@ -370,6 +362,7 @@ class TestResultController extends Controller
$imageExist = [];
$imagesDeleted = [];
foreach ($images as $key => $image) {
$imageExist[] = '/'.$image->path;
if (!in_array('/'.$image->path, $request->imgs)) {
$imagesDeleted[] = $image->path;
@@ -378,13 +371,13 @@ class TestResultController extends Controller
}
// strrpos($mystring, "base64")
if ($request->imgs != null) {
$request_imgs = array_diff($request->imgs, $imageExist);
foreach ($request_imgs as $key => $img) {//
$Image = $img;
$InterventionImage = Image::make($Image);
@@ -402,12 +395,14 @@ class TestResultController extends Controller
//--------------------------------------------------------
}
foreach ($imagesDeleted as $key => $imageDeleted) {
$Gallery = Gallery::where('path', $imageDeleted)->findOrFail();
if ($Gallery) {
Storage::disk('public')->delete(static::storage_path($imageDeleted));
Uploadable::where('gallery_id', $Gallery->id)->where('uploadable_id', $TestResult->id)->where('uploadable_type', get_class($TestResult))->delete();
$Gallery->delete();
if (count($imagesDeleted)) {
foreach ($imagesDeleted as $key => $imageDeleted) {
$Gallery = Gallery::where('path', $imageDeleted)->findOrFail();
if ($Gallery) {
Storage::disk('public')->delete(static::storage_path($imageDeleted));
Uploadable::where('gallery_id', $Gallery->id)->where('uploadable_id', $TestResult->id)->where('uploadable_type', get_class($TestResult))->delete();
$Gallery->delete();
}
}
}