-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
582d9b7
commit 7fdd703
Showing
12 changed files
with
477 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\BCRProjectResource\Pages; | ||
use App\Models\BCRProject; | ||
use Filament\Forms\Components\DatePicker; | ||
use Filament\Forms\Components\Repeater; | ||
use Filament\Forms\Components\Select; | ||
use Filament\Forms\Components\SpatieMediaLibraryFileUpload; | ||
use Filament\Forms\Components\Textarea; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Resources\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Resources\Table; | ||
use Filament\Tables; | ||
use Filament\Tables\Actions\DeleteAction; | ||
use Filament\Tables\Actions\EditAction; | ||
use Filament\Tables\Actions\ViewAction; | ||
use Filament\Tables\Columns\TextColumn; | ||
|
||
class BCRProjectResource extends Resource | ||
{ | ||
protected static ?string $model = BCRProject::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-collection'; | ||
|
||
protected static ?int $navigationSort = 7; | ||
|
||
public static function getPluralLabel(): ?string | ||
{ | ||
return __('bcr-project.label.plural'); | ||
} | ||
|
||
public static function getModelLabel(): string | ||
{ | ||
return __('bcr-project.label.singular'); | ||
} | ||
|
||
protected static function getNavigationGroup(): ?string | ||
{ | ||
return __('navigation.group.manage'); | ||
} | ||
|
||
protected static function getNavigationBadge(): ?string | ||
{ | ||
return (string) BCRProject::count(); | ||
} | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
TextInput::make('title') | ||
->label(__('bcr-project.labels.title')) | ||
->inlineLabel() | ||
->columnSpanFull() | ||
->required(), | ||
|
||
Select::make('category_id') | ||
->label(__('bcr-project.labels.category')) | ||
->relationship('category', 'name') | ||
->inlineLabel() | ||
->columnSpanFull() | ||
->required(), | ||
|
||
Select::make('county_id') | ||
->label(__('bcr-project.labels.county')) | ||
->relationship('county', 'name') | ||
->inlineLabel() | ||
->columnSpanFull() | ||
->required(), | ||
|
||
Textarea::make('description') | ||
->label(__('bcr-project.labels.description')) | ||
->inlineLabel() | ||
->columnSpanFull() | ||
->required(), | ||
|
||
DatePicker::make('start_date') | ||
->label(__('bcr-project.labels.start_date')) | ||
->inlineLabel() | ||
->columnSpanFull() | ||
->required(), | ||
|
||
DatePicker::make('end_date') | ||
->label(__('bcr-project.labels.end_date')) | ||
->inlineLabel() | ||
->columnSpanFull() | ||
->required(), | ||
|
||
TextInput::make('facebook_link') | ||
->label(__('bcr-project.labels.facebook_link')) | ||
->inlineLabel() | ||
->columnSpanFull() | ||
->required(), | ||
|
||
SpatieMediaLibraryFileUpload::make('preview') | ||
->collection('preview') | ||
->label(__('project.labels.preview_image')) | ||
->mediaName('preview') | ||
->image() | ||
->maxFiles(1) | ||
->inlineLabel() | ||
->columnSpanFull(), | ||
|
||
SpatieMediaLibraryFileUpload::make('gallery') | ||
->collection('gallery') | ||
->label(__('project.labels.gallery')) | ||
->image() | ||
->multiple() | ||
->maxFiles(20) | ||
->inlineLabel() | ||
->columnSpanFull(), | ||
|
||
Repeater::make('external_links') | ||
->schema([ | ||
TextInput::make('title') | ||
->label(__('bcr-project.labels.external_links.title')) | ||
->inlineLabel() | ||
->columnSpanFull() | ||
->required(), | ||
TextInput::make('link')->label(__('bcr-project.labels.external_links.link')) | ||
->inlineLabel() | ||
->columnSpanFull() | ||
->required(), | ||
]) | ||
->label(__('bcr-project.labels.external_links.label')) | ||
->inlineLabel() | ||
->columnSpanFull(), | ||
|
||
Repeater::make('videos') | ||
->schema([ | ||
TextInput::make('link')->label(__('bcr-project.labels.videos')) | ||
->inlineLabel() | ||
->columnSpanFull() | ||
->required(), | ||
]) | ||
->inlineLabel() | ||
->columnSpanFull(), | ||
|
||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
TextColumn::make('id') | ||
->formatStateUsing(function (BcrProject $record) { | ||
return sprintf('#%d', $record->id); | ||
}) | ||
->label(__('volunteer.column.id')) | ||
->sortable(), | ||
TextColumn::make('title') | ||
->label(__('bcr-project.labels.title')) | ||
->searchable() | ||
->sortable(), | ||
TextColumn::make('start_date') | ||
->label(__('bcr-project.labels.start_date')) | ||
->searchable() | ||
->sortable(), | ||
TextColumn::make('end_date') | ||
->label(__('bcr-project.labels.end_date')) | ||
->searchable() | ||
->sortable(), | ||
|
||
]) | ||
->filters([ | ||
// | ||
]) | ||
->actions([ | ||
ViewAction::make(), | ||
EditAction::make(), | ||
DeleteAction::make(), | ||
|
||
]) | ||
->bulkActions([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
])->defaultSort('id', 'desc'); | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListBCRProjects::route('/'), | ||
'create' => Pages\CreateBCRProject::route('/create'), | ||
'edit' => Pages\EditBCRProject::route('/{record}/edit'), | ||
]; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/Filament/Resources/BCRProjectResource/Pages/CreateBCRProject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\BCRProjectResource\Pages; | ||
|
||
use App\Filament\Resources\BCRProjectResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreateBCRProject extends CreateRecord | ||
{ | ||
protected static string $resource = BCRProjectResource::class; | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/BCRProjectResource/Pages/EditBCRProject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\BCRProjectResource\Pages; | ||
|
||
use App\Filament\Resources\BCRProjectResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditBCRProject extends EditRecord | ||
{ | ||
protected static string $resource = BCRProjectResource::class; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
Actions\DeleteAction::make(), | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/BCRProjectResource/Pages/ListBCRProjects.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\BCRProjectResource\Pages; | ||
|
||
use App\Filament\Resources\BCRProjectResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListBCRProjects extends ListRecords | ||
{ | ||
protected static string $resource = BCRProjectResource::class; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use App\Concerns\HasLocation; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Support\Facades\Vite; | ||
use Spatie\Image\Manipulations; | ||
use Spatie\MediaLibrary\HasMedia; | ||
use Spatie\MediaLibrary\InteractsWithMedia; | ||
use Spatie\MediaLibrary\MediaCollections\Models\Media; | ||
|
||
class BCRProject extends Model implements HasMedia | ||
{ | ||
use HasFactory; | ||
use HasLocation; | ||
use InteractsWithMedia; | ||
|
||
protected $fillable = [ | ||
'title', | ||
'description', | ||
'start_date', | ||
'end_date', | ||
'external_articles', | ||
'facebook_link', | ||
'accepting_comments', | ||
'videos', | ||
'city_id', | ||
'county_id', | ||
'project_category_id', | ||
'is_national', | ||
]; | ||
|
||
protected $casts = [ | ||
'external_links' => 'array', | ||
'videos' => 'array', | ||
'start_date' => 'datetime', | ||
'end_date' => 'datetime', | ||
'accepting_comments' => 'boolean', | ||
'is_national' => 'boolean', | ||
]; | ||
|
||
public function registerMediaCollections(): void | ||
{ | ||
$this->addMediaCollection('preview') | ||
->useFallbackUrl(Vite::image('placeholder.png')) | ||
->singleFile() | ||
->registerMediaConversions(function (Media $media) { | ||
$this | ||
->addMediaConversion('preview') | ||
->fit(Manipulations::FIT_CONTAIN, 300, 300) | ||
->nonQueued(); | ||
}); | ||
|
||
$this->addMediaCollection('gallery') | ||
->registerMediaConversions(function (Media $media) { | ||
$this | ||
->addMediaConversion('preview') | ||
->fit(Manipulations::FIT_CONTAIN, 300, 300) | ||
->nonQueued(); | ||
}); | ||
} | ||
|
||
public function category(): BelongsTo | ||
{ | ||
return $this->belongsTo(ProjectCategory::class, 'project_category_id'); | ||
} | ||
} |
Oops, something went wrong.