Skip to content

Commit

Permalink
Merge branch 'main' of github.com:vormkracht10/filament-media-picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Dec 7, 2024
2 parents c6a94dc + 069c5bb commit f3d9936
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 22 deletions.
20 changes: 6 additions & 14 deletions src/Concerns/HasMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Support\Collection;

trait HasMedia
{
/**
* Get all media associated with the model.
*
* @return MorphToMany
*/
public function media(): MorphToMany
{
Expand All @@ -28,9 +25,8 @@ public function media(): MorphToMany
/**
* Attach media to the model.
*
* @param string|array|\Illuminate\Support\Collection $media
* @param array $options Additional options for attachment
* @return self
* @param string|array|\Illuminate\Support\Collection $media
* @param array $options Additional options for attachment
*/
public function attachMedia($media, array $options = []): self
{
Expand Down Expand Up @@ -59,8 +55,7 @@ public function attachMedia($media, array $options = []): self
/**
* Detach media from the model.
*
* @param string|array|\Illuminate\Support\Collection $media
* @return self
* @param string|array|\Illuminate\Support\Collection $media
*/
public function detachMedia($media): self
{
Expand All @@ -80,9 +75,8 @@ public function detachMedia($media): self
/**
* Sync media attachments.
*
* @param string|array|\Illuminate\Support\Collection $media
* @param array $options Sync options
* @return self
* @param string|array|\Illuminate\Support\Collection $media
* @param array $options Sync options
*/
public function syncMedia($media, array $options = []): self
{
Expand All @@ -109,11 +103,9 @@ public function getFirstMediaAttribute()

/**
* Check if the model has any media attached.
*
* @return bool
*/
public function hasMedia(): bool
{
return $this->media()->exists();
}
}
}
2 changes: 1 addition & 1 deletion src/MediaPickerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,4 @@ protected function getMigrations(): array
'add_tenant_aware_column_to_media_table',
];
}
}
}
4 changes: 1 addition & 3 deletions src/Models/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public function getRouteKeyName(): string

/**
* Get all models this media is attached to.
*
* @return MorphToMany
*/
public function models(): MorphToMany
{
Expand Down Expand Up @@ -121,4 +119,4 @@ public function download(): \Symfony\Component\HttpFoundation\StreamedResponse

return Storage::disk($disk)->download($directory . '/' . $this->filename);

Check failure on line 120 in src/Models/Media.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Vormkracht10\MediaPicker\Models\Media::$filename.
}
}
}
2 changes: 1 addition & 1 deletion src/Pages/Media/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ public function deleteAction(): Action
}
});
}
}
}
6 changes: 3 additions & 3 deletions src/Resources/MediaResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static function form(Form $form): Form
->label(__('Model Type'))
->options(function () {
return collect(config('media-picker.file_upload.models'))
->mapWithKeys(fn($model) => [$model => class_basename($model)])
->mapWithKeys(fn ($model) => [$model => class_basename($model)])
->toArray();
})
->visible(count(config('media-picker.file_upload.models') ?? []) > 0)
Expand All @@ -117,7 +117,7 @@ public static function form(Form $form): Form
})
->visible(count(config('media-picker.file_upload.models') ?? []) > 0)
->columnSpan(1)
->disabled(fn(Get $get) => ! $get('model_type')),
->disabled(fn (Get $get) => ! $get('model_type')),
]),
]);
}
Expand Down Expand Up @@ -167,4 +167,4 @@ public static function getPages(): array
'edit' => MediaResource\EditMedia::route('/{record}/edit'),
];
}
}
}

0 comments on commit f3d9936

Please sign in to comment.