Skip to content

Commit 51f716c

Browse files
committed
feat: add frontend prototype for product resource
1 parent 46fd2fe commit 51f716c

2 files changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
3+
namespace Eclipse\Catalogue\Frontend\Filament\Resources;
4+
5+
use Eclipse\Catalogue\Frontend\Filament\Resources\ProductResource\Pages;
6+
use Eclipse\Catalogue\Models\Product;
7+
use Filament\Forms\Components\Checkbox;
8+
use Filament\Forms\Components\Placeholder;
9+
use Filament\Forms\Components\TextInput;
10+
use Filament\Forms\Form;
11+
use Filament\Resources\Resource;
12+
use Filament\Tables\Actions\BulkActionGroup;
13+
use Filament\Tables\Actions\DeleteAction;
14+
use Filament\Tables\Actions\DeleteBulkAction;
15+
use Filament\Tables\Actions\EditAction;
16+
use Filament\Tables\Columns\TextColumn;
17+
use Filament\Tables\Table;
18+
19+
class ProductResource extends Resource
20+
{
21+
protected static ?string $model = Product::class;
22+
23+
protected static ?string $slug = 'products';
24+
25+
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
26+
27+
public static function form(Form $form): Form
28+
{
29+
return $form
30+
->schema([
31+
TextInput::make('code'),
32+
33+
TextInput::make('barcode'),
34+
35+
TextInput::make('manufacturers_code'),
36+
37+
TextInput::make('suppliers_code'),
38+
39+
TextInput::make('net_weight')
40+
->numeric(),
41+
42+
TextInput::make('gross_weight')
43+
->numeric(),
44+
45+
Placeholder::make('created_at')
46+
->label('Created Date')
47+
->content(fn(?Product $record): string => $record?->created_at?->diffForHumans() ?? '-'),
48+
49+
Placeholder::make('updated_at')
50+
->label('Last Modified Date')
51+
->content(fn(?Product $record): string => $record?->updated_at?->diffForHumans() ?? '-'),
52+
53+
TextInput::make('category_id')
54+
->integer(),
55+
56+
Checkbox::make('registerMediaConversionsUsingModelInstance'),
57+
]);
58+
}
59+
60+
public static function table(Table $table): Table
61+
{
62+
return $table
63+
->columns([
64+
TextColumn::make('code'),
65+
66+
TextColumn::make('barcode'),
67+
68+
TextColumn::make('manufacturers_code'),
69+
70+
TextColumn::make('suppliers_code'),
71+
72+
TextColumn::make('net_weight'),
73+
74+
TextColumn::make('gross_weight'),
75+
76+
TextColumn::make('name')
77+
->searchable()
78+
->sortable(),
79+
80+
TextColumn::make('short_description'),
81+
82+
TextColumn::make('description'),
83+
84+
TextColumn::make('category_id'),
85+
86+
TextColumn::make('registerMediaConversionsUsingModelInstance'),
87+
])
88+
->filters([
89+
//
90+
])
91+
->actions([
92+
EditAction::make(),
93+
DeleteAction::make(),
94+
])
95+
->bulkActions([
96+
BulkActionGroup::make([
97+
DeleteBulkAction::make(),
98+
]),
99+
]);
100+
}
101+
102+
public static function getPages(): array
103+
{
104+
return [
105+
'index' => Pages\ListProducts::route('/'),
106+
];
107+
}
108+
109+
public static function getGloballySearchableAttributes(): array
110+
{
111+
return ['name'];
112+
}
113+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Eclipse\Catalogue\Frontend\Filament\Resources\ProductResource\Pages;
4+
5+
use Eclipse\Catalogue\Frontend\Filament\Resources\ProductResource;
6+
use Filament\Actions\CreateAction;
7+
use Filament\Resources\Pages\ListRecords;
8+
9+
class ListProducts extends ListRecords
10+
{
11+
protected static string $resource = ProductResource::class;
12+
13+
protected function getHeaderActions(): array
14+
{
15+
return [
16+
CreateAction::make(),
17+
];
18+
}
19+
}

0 commit comments

Comments
 (0)