for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Mostafaznv\Larupload\Concerns;
use Illuminate\Database\Eloquent\SoftDeletingScope;
trait LaruploadObservers
{
protected static function boot(): void
parent::boot();
static::saved(function($model) {
$shouldSave = false;
foreach ($model->attachments as $attachment) {
if (!$attachment->isUploaded()) {
$shouldSave = true;
$model = $attachment->saved($model);
}
if ($shouldSave) {
$model->save();
});
static::deleted(function($model) {
if (!$model->hasGlobalScope(SoftDeletingScope::class) or $model->isForceDeleting()) {
$attachment->deleted();
static::retrieved(function($model) {
$attachment->setOutput($model);