Skip to content

Commit 4a061f2

Browse files
committed
Updates for forum creation
1 parent 1efdb95 commit 4a061f2

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/Filament/Resources/Forums/ForumResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
use Filament\Tables\Columns\Layout\Stack;
1313
use Filament\Tables\Table;
1414
use Illuminate\Database\Eloquent\Model;
15-
use Tapp\FilamentForum\Filament\Resources\Admin\ForumResource\Schemas\ForumForm;
1615
use Tapp\FilamentForum\Filament\Resources\Forums\Pages\CreateForum;
1716
use Tapp\FilamentForum\Filament\Resources\Forums\Pages\ListForums;
1817
use Tapp\FilamentForum\Filament\Resources\Forums\Pages\ManageForumPosts;
1918
use Tapp\FilamentForum\Filament\Resources\Forums\Pages\ViewForum;
19+
use Tapp\FilamentForum\Filament\Resources\Forums\Schemas\ForumForm;
2020
use Tapp\FilamentForum\Filament\Tables\Components\ForumCardColumn;
2121
use Tapp\FilamentForum\Models\Forum;
2222

src/Filament/Resources/Forums/Pages/CreateForum.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@
88
class CreateForum extends CreateRecord
99
{
1010
protected static string $resource = ForumResource::class;
11+
12+
protected function mutateFormDataBeforeCreate(array $data): array
13+
{
14+
// Automatically set the owner to the currently logged-in user
15+
$data['owner_id'] = auth()->id();
16+
17+
return $data;
18+
}
1119
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Tapp\FilamentForum\Filament\Resources\Forums\Schemas;
4+
5+
use Filament\Forms\Components\Checkbox;
6+
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
7+
use Filament\Forms\Components\Textarea;
8+
use Filament\Forms\Components\TextInput;
9+
use Filament\Schemas\Components\Section;
10+
use Filament\Schemas\Schema;
11+
12+
class ForumForm
13+
{
14+
public static function configure(Schema $schema): Schema
15+
{
16+
return $schema
17+
->components([
18+
Section::make()
19+
->id('forumForm')
20+
->columnSpanFull()
21+
->columns(2)
22+
->schema([
23+
TextInput::make('name')
24+
->label(__('filament-forum::filament-forum.forum.form.label.name'))
25+
->required()
26+
->maxLength(255)
27+
->columnSpanFull(),
28+
Textarea::make('description')
29+
->label(__('filament-forum::filament-forum.forum.form.label.description'))
30+
->required()
31+
->columnSpanFull(),
32+
SpatieMediaLibraryFileUpload::make('image')
33+
->label(__('filament-forum::filament-forum.forum.form.label.image'))
34+
->collection('images')
35+
->columnSpanFull(),
36+
Checkbox::make('is_hidden')
37+
->label('Hidden Forum')
38+
->helperText('If checked, only assigned users can view this forum. If unchecked, all logged in users can view it.')
39+
->live(),
40+
]),
41+
]);
42+
}
43+
}

0 commit comments

Comments
 (0)