Init: Hoan thanh kien truc V3 va Filament UI
This commit is contained in:
73
app/Filament/Resources/Customers/CustomerResource.php
Normal file
73
app/Filament/Resources/Customers/CustomerResource.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Customers;
|
||||
|
||||
use App\Filament\Resources\Customers\Pages;
|
||||
use App\Models\Customer;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Fieldset;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class CustomerResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Customer::class;
|
||||
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-users';
|
||||
protected static string | \UnitEnum | null $navigationGroup = 'Quản lý Khách hàng';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Thông tin định danh')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('full_name')->label('Họ và Tên')->required(),
|
||||
TextInput::make('cmnd_cccd')->label('Số CMND / CCCD')->required()->unique(ignoreRecord: true),
|
||||
DatePicker::make('dob')->label('Ngày sinh')->displayFormat('d/m/Y'),
|
||||
]),
|
||||
Section::make('Thông liên lạc')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('phone')->label('Số điện thoại')->tel()->required(),
|
||||
TextInput::make('email')->label('Email')->email(),
|
||||
]),
|
||||
Section::make('Địa chỉ chi tiết')
|
||||
->schema([
|
||||
Fieldset::make('address')
|
||||
->label('Cấu trúc địa chỉ')->columns(3)
|
||||
->schema([
|
||||
TextInput::make('address.street')->label('Số nhà, đường')->columnSpan(3),
|
||||
TextInput::make('address.ward')->label('Phường / Xã'),
|
||||
TextInput::make('address.district')->label('Quận / Huyện'),
|
||||
TextInput::make('address.city')->label('Tỉnh / Thành phố'),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('full_name')->label('Họ Tên')->searchable(),
|
||||
Tables\Columns\TextColumn::make('cmnd_cccd')->label('CMND/CCCD')->searchable(),
|
||||
Tables\Columns\TextColumn::make('phone')->label('Điện thoại'),
|
||||
Tables\Columns\TextColumn::make('address.city')->label('Tỉnh/Thành')->sortable(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListCustomers::route('/'),
|
||||
'create' => Pages\CreateCustomer::route('/create'),
|
||||
'edit' => Pages\EditCustomer::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/Customers/Pages/CreateCustomer.php
Normal file
11
app/Filament/Resources/Customers/Pages/CreateCustomer.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Customers\Pages;
|
||||
|
||||
use App\Filament\Resources\Customers\CustomerResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateCustomer extends CreateRecord
|
||||
{
|
||||
protected static string $resource = CustomerResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/Customers/Pages/EditCustomer.php
Normal file
19
app/Filament/Resources/Customers/Pages/EditCustomer.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Customers\Pages;
|
||||
|
||||
use App\Filament\Resources\Customers\CustomerResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditCustomer extends EditRecord
|
||||
{
|
||||
protected static string $resource = CustomerResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Customers/Pages/ListCustomers.php
Normal file
19
app/Filament/Resources/Customers/Pages/ListCustomers.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Customers\Pages;
|
||||
|
||||
use App\Filament\Resources\Customers\CustomerResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListCustomers extends ListRecords
|
||||
{
|
||||
protected static string $resource = CustomerResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Filament/Resources/Customers/Schemas/CustomerForm.php
Normal file
31
app/Filament/Resources/Customers/Schemas/CustomerForm.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Customers\Schemas;
|
||||
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class CustomerForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('full_name')
|
||||
->required(),
|
||||
TextInput::make('cmnd_cccd')
|
||||
->required(),
|
||||
TextInput::make('phone')
|
||||
->tel(),
|
||||
TextInput::make('email')
|
||||
->label('Email address')
|
||||
->email(),
|
||||
TextInput::make('address_permanent'),
|
||||
TextInput::make('address_contact'),
|
||||
DatePicker::make('dob'),
|
||||
DatePicker::make('id_issue_date'),
|
||||
TextInput::make('id_issue_place'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
61
app/Filament/Resources/Customers/Tables/CustomersTable.php
Normal file
61
app/Filament/Resources/Customers/Tables/CustomersTable.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Customers\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class CustomersTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('ID'),
|
||||
TextColumn::make('full_name')
|
||||
->searchable(),
|
||||
TextColumn::make('cmnd_cccd')
|
||||
->searchable(),
|
||||
TextColumn::make('phone')
|
||||
->searchable(),
|
||||
TextColumn::make('email')
|
||||
->label('Email address')
|
||||
->searchable(),
|
||||
TextColumn::make('address_permanent')
|
||||
->searchable(),
|
||||
TextColumn::make('address_contact')
|
||||
->searchable(),
|
||||
TextColumn::make('dob')
|
||||
->date()
|
||||
->sortable(),
|
||||
TextColumn::make('id_issue_date')
|
||||
->date()
|
||||
->sortable(),
|
||||
TextColumn::make('id_issue_place')
|
||||
->searchable(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user