Skip to content

Commit

Permalink
Move before create to handle record creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Dec 1, 2024
1 parent 23a20ff commit 0d8c3eb
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Resources/MediaResource/CreateMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Vormkracht10\MediaPicker\Resources\MediaResource;

use Filament\Facades\Filament;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Vormkracht10\MediaPicker\MediaPickerPlugin;
use Filament\Resources\Pages\CreateRecord;
use Vormkracht10\MediaPicker\Models\Media;
use Vormkracht10\MediaPicker\MediaPickerPlugin;

class CreateMedia extends CreateRecord
{
Expand All @@ -15,7 +16,7 @@ public static function getResource(): string
return MediaPickerPlugin::get()->getResource();
}

protected function mutateFormDataBeforeCreate(array $data): array
protected function handleRecordCreation(array $data): Model
{
foreach ($data['media'] as $file) {
// Get the full path on the configured disk
Expand Down Expand Up @@ -51,7 +52,7 @@ protected function mutateFormDataBeforeCreate(array $data): array
}
}

Media::create([
$first = Media::create([
'site_ulid' => Filament::getTenant()->ulid,

Check failure on line 56 in src/Resources/MediaResource/CreateMedia.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Illuminate\Database\Eloquent\Model::$ulid.
'model_type' => $data['model_type'] ?? null,
'model_id' => $data['model_id'] ?? null,
Expand All @@ -69,8 +70,7 @@ protected function mutateFormDataBeforeCreate(array $data): array
]);
}

return [];

return $data;
return $first;

Check failure on line 73 in src/Resources/MediaResource/CreateMedia.php

View workflow job for this annotation

GitHub Actions / phpstan

Variable $first might not be defined.
// return static::getModel()::create($data);
}
}
}

0 comments on commit 0d8c3eb

Please sign in to comment.