Skip to content

Commit

Permalink
Remove model selection from upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Dec 7, 2024
1 parent 9985158 commit b047971
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 48 deletions.
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ return [
'navigation_count_badge' => false,
'resource' => \Vormkracht10\MediaPicker\Resources\MediaResource::class,
],

'file_upload' => [
'models' => [
// App\Models\User::class,
// App\Models\Blog::class,
],
],
];
```

Expand Down Expand Up @@ -121,13 +114,9 @@ public function panel(Panel $panel): Panel

If you are using tenancy, you can set the `is_tenant_aware` config option to `true` and set the `tenant_ownership_relationship_name` and `tenant_relationship` config options to the names of the relationships on the media model and the tenant model, respectively. You can also set the `tenant_model` config option to the fully qualified class name of the tenant model.

### File upload

If you want to be able to setup a relationship between a model and a media file, you can add the model to the `models` array in the `file_upload` config option. This will add a select field to the media form that allows you to select the model that the media file belongs to. You can then use the `Vormkracht10\MediaPicker\Concerns\HasMedia` trait on the model to setup the relationship.

### Manually define the relationship between a model and a media file
### File upload (with relationship)

Use the `Vormkracht10\MediaPicker\Concerns\HasMedia` trait on the model to setup the relationship between the model and the media file. You can then use the following methods to define the relationship:
If you want to be able to setup a relationship between a model and a media file, you can add the `Vormkracht10\MediaPicker\Concerns\HasMedia` trait on the model to easily attach a media file to the model. You can then use the following methods to define the relationship:

```php
$model->attachMedia($mediaUlid);
Expand Down
9 changes: 1 addition & 8 deletions config/media-picker.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,4 @@
'navigation_count_badge' => false,
'resource' => \Vormkracht10\MediaPicker\Resources\MediaResource::class,
],

'file_upload' => [
'models' => [
// App\Models\User::class,
// App\Models\Blog::class,
],
],
];
];
28 changes: 1 addition & 27 deletions src/Resources/MediaResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,6 @@ public static function form(Form $form): Form
->schema([
MediaPicker::make()
->required(),

Select::make('model_type')
->label(__('Model Type'))
->options(function () {
return collect(config('media-picker.file_upload.models'))
->mapWithKeys(fn ($model) => [$model => class_basename($model)])
->toArray();
})
->visible(count(config('media-picker.file_upload.models') ?? []) > 0)
->columnSpan(1)
->live(),

Select::make('model_id')
->label(__('Model'))
->options(function (Get $get) {
$selectedModelType = $get('model_type');

if (! $selectedModelType) {
return [];
}

return $selectedModelType::all()->pluck('name', 'id');
})
->visible(count(config('media-picker.file_upload.models') ?? []) > 0)
->columnSpan(1)
->disabled(fn (Get $get) => ! $get('model_type')),
]),
]);
}
Expand Down Expand Up @@ -167,4 +141,4 @@ public static function getPages(): array
'edit' => MediaResource\EditMedia::route('/{record}/edit'),
];
}
}
}

0 comments on commit b047971

Please sign in to comment.