Skip to content

Commit be4e249

Browse files
post content type
1 parent 83c68a4 commit be4e249

28 files changed

+409
-171
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ yarn-error.log
2222
/.nova
2323
/.vscode
2424
/.zed
25+
/public/assets
26+
/public/assets

app/Filament/Imports/Blog/CategoryImporter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public function resolveRecord(): ?Category
5050

5151
public static function getCompletedNotificationBody(Import $import): string
5252
{
53-
$body = 'Your blog category import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
53+
$body = 'Your blog category import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
5454

5555
if ($failedRowsCount = $import->getFailedRowsCount()) {
56-
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
56+
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
5757
}
5858

5959
return $body;

app/Filament/Resources/Blog/CategoryResource.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public static function form(Form $form): Form
4040
->afterStateUpdated(fn (string $operation, $state, Forms\Set $set) => $operation === 'create' ? $set('slug', Str::slug($state)) : null),
4141

4242
Forms\Components\TextInput::make('slug')
43-
->disabled()
4443
->dehydrated()
4544
->required()
4645
->maxLength(255)

app/Filament/Resources/Blog/LinkResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static function infolist(Infolist $infolist): Infolist
6565
TextEntry::make('url')
6666
->label('URL')
6767
->columnSpanFull()
68-
->url(fn (Link $record): string => '#' . urlencode($record->url)),
68+
->url(fn (Link $record): string => '#'.urlencode($record->url)),
6969
ImageEntry::make('image'),
7070
]);
7171
}
@@ -114,7 +114,7 @@ public static function table(Table $table): Table
114114
->label('Visit link')
115115
->icon('heroicon-m-arrow-top-right-on-square')
116116
->color('gray')
117-
->url(fn (Link $record): string => '#' . urlencode($record->url)),
117+
->url(fn (Link $record): string => '#'.urlencode($record->url)),
118118
Tables\Actions\EditAction::make(),
119119
])
120120
->bulkActions([

app/Filament/Resources/Blog/PostResource.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Illuminate\Database\Eloquent\Model;
2121
use Illuminate\Support\Carbon;
2222
use Illuminate\Support\Str;
23+
use Mohamedsabil83\FilamentFormsTinyeditor\Components\TinyEditor;
2324

2425
class PostResource extends Resource
2526
{
@@ -50,14 +51,38 @@ public static function form(Form $form): Form
5051
->afterStateUpdated(fn (string $operation, $state, Forms\Set $set) => $operation === 'create' ? $set('slug', Str::slug($state)) : null),
5152

5253
Forms\Components\TextInput::make('slug')
53-
->disabled()
5454
->dehydrated()
5555
->required()
5656
->maxLength(255)
5757
->unique(Post::class, 'slug', ignoreRecord: true),
5858

59+
Forms\Components\Radio::make('content_type')
60+
->label('Content Type')
61+
->options([
62+
'markdown' => 'Markdown',
63+
'html' => 'HTML',
64+
])
65+
->default('markdown')
66+
->required()
67+
->reactive()
68+
->inline(),
69+
5970
Forms\Components\MarkdownEditor::make('content')
6071
->required()
72+
->fileAttachmentsDirectory('blog/posts/content')
73+
->getUploadedAttachmentUrlUsing(fn ($file): string => str(diskPublic()->url($file))->replace(
74+
config('app.url'),
75+
''
76+
))
77+
->visible(fn ($get) => $get('content_type') === 'markdown')
78+
->columnSpan('full'),
79+
80+
TinyEditor::make('content')
81+
->required()
82+
->maxHeight(600)
83+
->showMenuBar()
84+
->fileAttachmentsDirectory('blog/posts/content')
85+
->visible(fn ($get) => $get('content_type') === 'html')
6186
->columnSpan('full'),
6287

6388
Forms\Components\Select::make('blog_author_id')

app/Filament/Resources/Blog/PostResource/Pages/EditPost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class EditPost extends EditRecord
1212
{
1313
protected static string $resource = PostResource::class;
1414

15-
public function getTitle(): string | Htmlable
15+
public function getTitle(): string|Htmlable
1616
{
1717
/** @var Post */
1818
$record = $this->getRecord();

app/Filament/Resources/Blog/PostResource/Pages/ViewPost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ViewPost extends ViewRecord
1111
{
1212
protected static string $resource = PostResource::class;
1313

14-
public function getTitle(): string | Htmlable
14+
public function getTitle(): string|Htmlable
1515
{
1616
/** @var Post */
1717
$record = $this->getRecord();

app/Models/Blog/Category.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@
66
use Illuminate\Database\Eloquent\Model;
77
use Illuminate\Database\Eloquent\Relations\HasMany;
88

9+
/**
10+
* @property int $id
11+
* @property string $name
12+
* @property string $slug
13+
* @property string|null $description
14+
* @property bool $is_visible
15+
* @property string|null $seo_title
16+
* @property string|null $seo_description
17+
* @property \Illuminate\Support\Carbon|null $created_at
18+
* @property \Illuminate\Support\Carbon|null $updated_at
19+
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Blog\Post> $posts
20+
* @property-read int|null $posts_count
21+
*
22+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Category newModelQuery()
23+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Category newQuery()
24+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Category query()
25+
*
26+
* @mixin \Illuminate\Database\Eloquent\Model
27+
*/
928
class Category extends Model
1029
{
1130
use HasFactory;
@@ -27,16 +46,19 @@ class Category extends Model
2746
'seo_description',
2847
];
2948

30-
/**
31-
* @var array<string, string>
32-
*/
33-
protected $casts = [
34-
'is_visible' => 'boolean',
35-
];
36-
3749
/** @return HasMany<Post> */
3850
public function posts(): HasMany
3951
{
4052
return $this->hasMany(Post::class, 'blog_category_id');
4153
}
54+
55+
/**
56+
* @return array<string, string>
57+
*/
58+
protected function casts(): array
59+
{
60+
return [
61+
'is_visible' => 'boolean',
62+
];
63+
}
4264
}

app/Models/Blog/Link.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@
66
use Illuminate\Database\Eloquent\Model;
77
use Spatie\Translatable\HasTranslations;
88

9+
/**
10+
* @property int $id
11+
* @property string $url
12+
* @property array<array-key, mixed> $title
13+
* @property array<array-key, mixed> $description
14+
* @property string $color
15+
* @property string|null $image
16+
* @property \Illuminate\Support\Carbon|null $created_at
17+
* @property \Illuminate\Support\Carbon|null $updated_at
18+
* @property-read mixed $translations
19+
*
20+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Link newModelQuery()
21+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Link newQuery()
22+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Link query()
23+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Link whereJsonContainsLocale(string $column, string $locale, ?mixed $value, string $operand = '=')
24+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Link whereJsonContainsLocales(string $column, array $locales, ?mixed $value, string $operand = '=')
25+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Link whereLocale(string $column, string $locale)
26+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Link whereLocales(string $column, array $locales)
27+
*
28+
* @mixin \Illuminate\Database\Eloquent\Model
29+
*/
930
class Link extends Model
1031
{
1132
use HasFactory;

app/Models/Blog/Post.php

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,39 @@
1010
use Illuminate\Database\Eloquent\Relations\MorphMany;
1111
use Spatie\Tags\HasTags;
1212

13+
/**
14+
* @property int $id
15+
* @property int|null $blog_author_id
16+
* @property int|null $blog_category_id
17+
* @property string $title
18+
* @property string $slug
19+
* @property string $content_type markdown, html
20+
* @property string $content
21+
* @property \Illuminate\Support\Carbon|null $published_at
22+
* @property string|null $seo_title
23+
* @property string|null $seo_description
24+
* @property string|null $image
25+
* @property \Illuminate\Support\Carbon|null $created_at
26+
* @property \Illuminate\Support\Carbon|null $updated_at
27+
* @property-read User|null $author
28+
* @property-read \App\Models\Blog\Category|null $category
29+
* @property-read \Illuminate\Database\Eloquent\Collection<int, Comment> $comments
30+
* @property-read int|null $comments_count
31+
* @property \Illuminate\Database\Eloquent\Collection<int, \Spatie\Tags\Tag> $tags
32+
* @property-read int|null $tags_count
33+
*
34+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post newModelQuery()
35+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post newQuery()
36+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post query()
37+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post withAllTags(\ArrayAccess|\Spatie\Tags\Tag|array|string $tags, ?string $type = null)
38+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post withAllTagsOfAnyType($tags)
39+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post withAnyTags(\ArrayAccess|\Spatie\Tags\Tag|array|string $tags, ?string $type = null)
40+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post withAnyTagsOfAnyType($tags)
41+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post withAnyTagsOfType(array|string $type)
42+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Post withoutTags(\ArrayAccess|\Spatie\Tags\Tag|array|string $tags, ?string $type = null)
43+
*
44+
* @mixin \Illuminate\Database\Eloquent\Model
45+
*/
1346
class Post extends Model
1447
{
1548
use HasFactory;
@@ -28,20 +61,14 @@ class Post extends Model
2861
'blog_category_id',
2962
'title',
3063
'slug',
64+
'content_type',
3165
'content',
3266
'published_at',
3367
'seo_title',
3468
'seo_description',
3569
'image',
3670
];
3771

38-
/**
39-
* @var array<string, string>
40-
*/
41-
protected $casts = [
42-
'published_at' => 'date',
43-
];
44-
4572
/** @return BelongsTo<User,self> */
4673
public function author(): BelongsTo
4774
{
@@ -59,4 +86,14 @@ public function comments(): MorphMany
5986
{
6087
return $this->morphMany(Comment::class, 'commentable');
6188
}
89+
90+
/**
91+
* @return array<string, string>
92+
*/
93+
protected function casts(): array
94+
{
95+
return [
96+
'published_at' => 'date',
97+
];
98+
}
6299
}

0 commit comments

Comments
 (0)