File: D:/HostingSpaces/SBogers10/reiskick.komma.nl/app/Components/Component.php
<?php declare(strict_types=1);
namespace App\Components;
use App\Pages\Models\Page;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Support\Facades\App;
use Komma\KMS\Components\Component\Component as KmsComponent;
use Komma\KMS\Components\Component\ViewComponent;
use Komma\Kms\Components\ComponentArea\ComponentArea;
class Component extends KmsComponent
{
/**
* @return BelongsTo
*/
public function componentArea(): BelongsTo {
return $this->belongsTo(ComponentArea::class);
}
public function pages(): MorphToMany
{
return $this->morphedByMany(Page::class, 'componentable');
}
public static function cleanUp($viewComponent) {
if( App::environment('local') ) return;
if(!isset($viewComponent->image) || $viewComponent->image->isEmpty()) return;
foreach ($viewComponent->image as $image) {
if($image->file_system_path !== '') {
$absolutePath = public_path($image->file_system_path);
if ($absolutePath != public_path() && file_exists($absolutePath)) {
if (!unlink($absolutePath)) {
throw new \RuntimeException(self::class . ': Could not delete file: ' . $absolutePath);
}
}
$image->file_system_path = '';
$image->save();
}
}
}
}