fix: images from static pages are now saved in the storage folder

This commit is contained in:
Corentin Huet 2025-10-06 12:42:48 +02:00
parent 4f02895ac8
commit ee912e4163
2 changed files with 16 additions and 1 deletions

3
.gitignore vendored
View file

@ -23,6 +23,9 @@ Homestead.yaml
npm-debug.log
yarn-error.log
.npmrc
.zshrc
.npm/
.composer/
# Ignore public favicon
/public/android-chrome-192x192.png

View file

@ -3,6 +3,7 @@
namespace App\Models;
use App\Enums\StaticPageType;
use App\Lib\Helpers\FileStorageHelper;
use App\Lib\Helpers\ToolboxHelper;
use App\Traits\Models\ActivityLog;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@ -17,6 +18,9 @@ use Illuminate\Support\Str;
* @property string $title Title for the page.
* @property string $slug Slug of the title for the page.
* @property string $content WYSIWYG text content using ckeditor.
* @property string $picture Slide picture path.
* @property string $picture_alt Slide picture alt attribute.
* @property string $picture_title Slide picture title attribute.
* @property-read \Illuminate\Support\Carbon $created_at Created date.
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
*
@ -37,6 +41,9 @@ class StaticPage extends Model
'seo_description',
'title',
'content',
'picture',
'picture_alt',
'picture_title',
];
/**
@ -61,6 +68,9 @@ class StaticPage extends Model
static::updating(function (self $model) {
self::manageFields($model);
});
static::updated(function (self $model) {
FileStorageHelper::removeOldFile($model, 'picture');
});
}
// * ROUTABLE
@ -105,7 +115,9 @@ class StaticPage extends Model
ToolboxHelper::assertNoInternalBoUrls('content', $model->content);
$model->content = clean($model->content);
}
if ($model->picture) {
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
}
// * TRANSFORMATIONS
self::setSlug($model, $model->title);
}