Skip to content

Commit

Permalink
fix: video url type error (#393)
Browse files Browse the repository at this point in the history
* fix: video url type error

* fix: add video repeater validation rules
  • Loading branch information
andreiio authored Aug 8, 2024
1 parent 24ef181 commit 7a00a83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions app/Filament/Resources/ProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ function (callable $get) {
->image()
->multiple()
->maxFiles(20),
Forms\Components\Repeater::make('videos')->schema([
TextInput::make('url'),
]),
Forms\Components\Repeater::make('videos')
->schema([
TextInput::make('url')
->url()
->required(),
]),
Forms\Components\Repeater::make('external_links')->schema([
TextInput::make('title')
->required(),
Expand Down
6 changes: 4 additions & 2 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Vite;
use Illuminate\Support\Str;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Image\Manipulations;
Expand Down Expand Up @@ -241,7 +242,7 @@ public function getVisibleStatusAttribute(): string

public function markAsApproved(): bool
{
$slug = \Str::slug($this->name);
$slug = Str::slug($this->name);

$count = self::whereRaw("slug RLIKE '^{$this->slug}(-[0-9]+)?$'")->count();
if ($count > 0) {
Expand Down Expand Up @@ -275,11 +276,12 @@ public function getEmbeddedVideosAttribute(): array
{
return collect($this->videos)
->pluck('url')
->filter()
->map(
fn (string $videoUrl) => Cache::remember(
'video-' . hash('sha256', $videoUrl),
MONTH_IN_SECONDS,
fn () => rescue(fn () => (new Embed)->get($videoUrl)->code, '', false)
fn () => rescue(fn () => (new Embed)->get($videoUrl)->code, report: false)
)
)
->filter()
Expand Down

0 comments on commit 7a00a83

Please sign in to comment.