From ed483110da36bd137eef1f1eaa9053deae98bb51 Mon Sep 17 00:00:00 2001 From: Arthur Monney Date: Tue, 17 Dec 2024 14:28:46 +0100 Subject: [PATCH 1/2] fix: [LAR-130] relation on ArticleForm --- .../Components/Slideovers/ArticleForm.php | 80 ++++++++++--------- app/Livewire/Pages/Account/Profile.php | 5 +- app/Models/Article.php | 11 +-- app/Providers/AppServiceProvider.php | 1 - lang/fr/pages/article.php | 2 +- 5 files changed, 47 insertions(+), 52 deletions(-) diff --git a/app/Livewire/Components/Slideovers/ArticleForm.php b/app/Livewire/Components/Slideovers/ArticleForm.php index 452de860..d3ce7949 100644 --- a/app/Livewire/Components/Slideovers/ArticleForm.php +++ b/app/Livewire/Components/Slideovers/ArticleForm.php @@ -37,17 +37,15 @@ final class ArticleForm extends SlideOverComponent implements HasForms public function mount(?int $articleId = null): void { - /** @var Article $article */ - $article = $articleId + // @phpstan-ignore-next-line + $this->article = $articleId ? Article::query()->findOrFail($articleId) : new Article; - $this->form->fill(array_merge($article->toArray(), [ - 'is_draft' => ! $article->published_at, - 'published_at' => $article->published_at, + $this->form->fill(array_merge($this->article->toArray(), [ + 'is_draft' => ! $this->article->published_at, // @phpstan-ignore-line + 'published_at' => $this->article->published_at, // @phpstan-ignore-line ])); - - $this->article = $article; } public static function panelMaxWidth(): string @@ -78,55 +76,61 @@ public function form(Form $form): Form ->live(onBlur: true) ->afterStateUpdated(fn ($state, Forms\Set $set) => $set('slug', Str::slug($state))), Forms\Components\Hidden::make('slug'), + Forms\Components\TextInput::make('canonical_url') + ->label(__('pages/article.form.canonical_url')) + ->helperText(__('pages/article.canonical_help')), + Forms\Components\Grid::make() + ->schema([ + Forms\Components\Toggle::make('is_draft') + ->label(__('pages/article.form.draft')) + ->live() + ->offIcon('untitledui-check') + ->onColor('success') + ->onIcon('untitledui-pencil-line') + ->helperText(__('pages/article.draft_help')), + Forms\Components\DatePicker::make('published_at') + ->label(__('pages/article.form.published_at')) + ->minDate(now()) + ->prefixIcon('untitledui-calendar-date') + ->native(false) + ->visible(fn (Forms\Get $get): bool => $get('is_draft') === false) + ->required(fn (Forms\Get $get): bool => $get('is_draft') === false), + ]), + ]) + ->columnSpan(2), + Forms\Components\Group::make() + ->schema([ + Forms\Components\SpatieMediaLibraryFileUpload::make('media') + ->collection('media') + ->label(__('pages/article.form.cover')) + ->maxSize(1024), Forms\Components\Select::make('tags') - ->label(__('Tags')) + ->multiple() ->relationship( + name: 'tags', titleAttribute: 'name', - modifyQueryUsing: fn (Builder $query): Builder => $query->whereJsonContains('concerns', ['post']) + modifyQueryUsing: fn ($query) => $query->whereJsonContains('concerns', 'post') ) - ->searchable() ->preload() - ->multiple() ->required() ->minItems(1) ->maxItems(3), + ]) + ->columnSpan(1), + Forms\Components\Group::make() + ->schema([ Forms\Components\MarkdownEditor::make('body') ->label(__('validation.attributes.content')) ->fileAttachmentsDisk('public') ->minLength(10) - ->minHeight('20.25rem') - ->maxHeight('32.75rem') + ->maxHeight('20.25rem') ->required(), Forms\Components\Placeholder::make('') ->content(fn () => new HtmlString(Blade::render(<<<'Blade' Blade))), ]) - ->columnSpan(2), - Forms\Components\Group::make() - ->schema([ - Forms\Components\SpatieMediaLibraryFileUpload::make('media') - ->collection('media') - ->label(__('pages/article.form.cover')) - ->maxSize(1024), - Forms\Components\Toggle::make('is_draft') - ->label(__('pages/article.form.draft')) - ->live() - ->offIcon('untitledui-check') - ->onColor('success') - ->onIcon('untitledui-pencil-line') - ->helperText(__('pages/article.draft_help')), - Forms\Components\DatePicker::make('published_at') - ->label(__('pages/article.form.published_at')) - ->minDate(now()) - ->native(false) - ->visible(fn (Forms\Get $get): bool => $get('is_draft') === false) - ->required(fn (Forms\Get $get): bool => $get('is_draft') === false), - Forms\Components\TextInput::make('canonical_url') - ->label(__('pages/article.form.canonical_url')) - ->helperText(__('pages/article.canonical_help')), - ]) - ->columnSpan(1), + ->columnSpanFull(), ]) ->columns(3) ->statePath('data') diff --git a/app/Livewire/Pages/Account/Profile.php b/app/Livewire/Pages/Account/Profile.php index f13c0235..52c26445 100644 --- a/app/Livewire/Pages/Account/Profile.php +++ b/app/Livewire/Pages/Account/Profile.php @@ -27,8 +27,9 @@ public function mount(User $user): void public function render(): View { return view('livewire.pages.account.profile', [ - 'articles' => $this->user->articles() - ->scopes(['recent', 'published']) + 'articles' => $this->user->articles() // @phpstan-ignore-line + ->recent() + ->published() ->limit(5) ->get(), 'threads' => $this->user->threads() diff --git a/app/Models/Article.php b/app/Models/Article.php index 55300838..9c37cc37 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -42,6 +42,7 @@ * @property \Illuminate\Support\Carbon | null $sponsored_at * @property \Illuminate\Support\Carbon $created_at * @property \Illuminate\Support\Carbon $updated_at + * @property \Illuminate\Database\Eloquent\Collection | Tag[] $tags */ #[ScopedBy([LocaleScope::class])] final class Article extends Model implements HasMedia, ReactableInterface, Viewable @@ -236,14 +237,4 @@ public function delete(): ?bool return parent::delete(); } - - public function scopePublished(): Builder - { - return self::published(); - } - - public function scopeRecent(): Builder - { - return self::recent(); - } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 62a666b9..ac5bb1d8 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -43,7 +43,6 @@ public function boot(): void FilamentColor::register([ 'primary' => Color::Emerald, 'danger' => Color::Red, - 'gray' => Color::Gray, 'info' => Color::Blue, 'success' => Color::Green, 'warning' => Color::Amber, diff --git a/lang/fr/pages/article.php b/lang/fr/pages/article.php index f5fdfb13..0e569e01 100644 --- a/lang/fr/pages/article.php +++ b/lang/fr/pages/article.php @@ -24,7 +24,7 @@ 'published_at' => 'Date de publication', 'canonical_url' => 'URL Canonique', ], - 'canonical_help' => 'Modifiez si l\'article a été publié pour la première fois ailleurs (comme sur votre propre blog).', + 'canonical_help' => 'Précisez si l\'article a été publié pour la première fois ailleurs (comme sur votre propre blog).', 'draft_help' => 'Mettre en article en brouillon vous donne la possibilité de le modifier plus tard', 'unpublished' => 'Cet article n\'a pas encore été publié.', From 8f93ec53e15f0bf0e3f39c172dbcf68462d80602 Mon Sep 17 00:00:00 2001 From: Arthur Monney Date: Tue, 17 Dec 2024 14:32:05 +0100 Subject: [PATCH 2/2] chore: [LAR-130] apply laravel pint --- app/Livewire/Components/Slideovers/ArticleForm.php | 1 - app/Models/Article.php | 1 - 2 files changed, 2 deletions(-) diff --git a/app/Livewire/Components/Slideovers/ArticleForm.php b/app/Livewire/Components/Slideovers/ArticleForm.php index d3ce7949..f7660a35 100644 --- a/app/Livewire/Components/Slideovers/ArticleForm.php +++ b/app/Livewire/Components/Slideovers/ArticleForm.php @@ -16,7 +16,6 @@ use Filament\Forms\Form; use Filament\Notifications\Notification; use Illuminate\Contracts\View\View; -use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Blade; use Illuminate\Support\HtmlString; diff --git a/app/Models/Article.php b/app/Models/Article.php index 9c37cc37..38e1135c 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -14,7 +14,6 @@ use App\Traits\RecordsActivity; use CyrildeWit\EloquentViewable\Contracts\Viewable; use CyrildeWit\EloquentViewable\InteractsWithViews; -use Illuminate\Contracts\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Attributes\ScopedBy; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model;