Add Customer resource to Filament admin panel: Implemented Customer model, resource, and associated pages (create, edit, list). Defined customer form schema and table configuration. Added migration for customers table.
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Admin\Resources\Customers;
|
||||||
|
|
||||||
|
use App\Filament\Admin\Resources\Customers\Pages\CreateCustomer;
|
||||||
|
use App\Filament\Admin\Resources\Customers\Pages\EditCustomer;
|
||||||
|
use App\Filament\Admin\Resources\Customers\Pages\ListCustomers;
|
||||||
|
use App\Filament\Admin\Resources\Customers\Schemas\CustomerForm;
|
||||||
|
use App\Filament\Admin\Resources\Customers\Tables\CustomersTable;
|
||||||
|
use App\Models\Customer;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class CustomerResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Customer::class;
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||||
|
|
||||||
|
public static function form(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return CustomerForm::configure($schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return CustomersTable::configure($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListCustomers::route('/'),
|
||||||
|
'create' => CreateCustomer::route('/create'),
|
||||||
|
'edit' => EditCustomer::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Admin\Resources\Customers\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Admin\Resources\Customers\CustomerResource;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateCustomer extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = CustomerResource::class;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Admin\Resources\Customers\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Admin\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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Admin\Resources\Customers\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Admin\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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Admin\Resources\Customers\Schemas;
|
||||||
|
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
|
||||||
|
class CustomerForm
|
||||||
|
{
|
||||||
|
public static function configure(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->components([
|
||||||
|
\Filament\Forms\Components\TextInput::make('name')
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
\Filament\Forms\Components\TextInput::make('email')
|
||||||
|
->email()
|
||||||
|
->required()
|
||||||
|
->unique(ignoreRecord: true)
|
||||||
|
->maxLength(255),
|
||||||
|
\Filament\Forms\Components\TextInput::make('phone')
|
||||||
|
->tel()
|
||||||
|
->maxLength(255),
|
||||||
|
\Filament\Forms\Components\Textarea::make('address')
|
||||||
|
->maxLength(65535)
|
||||||
|
->columnSpanFull(),
|
||||||
|
\Filament\Forms\Components\TextInput::make('city')
|
||||||
|
->maxLength(255),
|
||||||
|
\Filament\Forms\Components\TextInput::make('country')
|
||||||
|
->maxLength(255),
|
||||||
|
\Filament\Forms\Components\Select::make('status')
|
||||||
|
->options([
|
||||||
|
'active' => 'Active',
|
||||||
|
'inactive' => 'Inactive',
|
||||||
|
'pending' => 'Pending',
|
||||||
|
])
|
||||||
|
->default('active')
|
||||||
|
->required(),
|
||||||
|
\Filament\Forms\Components\Textarea::make('notes')
|
||||||
|
->maxLength(65535)
|
||||||
|
->columnSpanFull(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Admin\Resources\Customers\Tables;
|
||||||
|
|
||||||
|
use Filament\Actions\BulkActionGroup;
|
||||||
|
use Filament\Actions\DeleteBulkAction;
|
||||||
|
use Filament\Actions\EditAction;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class CustomersTable
|
||||||
|
{
|
||||||
|
public static function configure(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
\Filament\Tables\Columns\TextColumn::make('name')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
\Filament\Tables\Columns\TextColumn::make('email')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
\Filament\Tables\Columns\TextColumn::make('phone')
|
||||||
|
->searchable(),
|
||||||
|
\Filament\Tables\Columns\TextColumn::make('city')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
\Filament\Tables\Columns\TextColumn::make('country')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
\Filament\Tables\Columns\TextColumn::make('status')
|
||||||
|
->badge()
|
||||||
|
->color(fn (string $state): string => match ($state) {
|
||||||
|
'active' => 'success',
|
||||||
|
'inactive' => 'danger',
|
||||||
|
'pending' => 'warning',
|
||||||
|
}),
|
||||||
|
\Filament\Tables\Columns\TextColumn::make('created_at')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
//
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
EditAction::make(),
|
||||||
|
])
|
||||||
|
->toolbarActions([
|
||||||
|
BulkActionGroup::make([
|
||||||
|
DeleteBulkAction::make(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Customer extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'email',
|
||||||
|
'phone',
|
||||||
|
'address',
|
||||||
|
'city',
|
||||||
|
'country',
|
||||||
|
'status',
|
||||||
|
'notes',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'created_at' => 'datetime',
|
||||||
|
'updated_at' => 'datetime',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('customers', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
|
$table->string('email')->unique();
|
||||||
|
$table->string('phone')->nullable();
|
||||||
|
$table->text('address')->nullable();
|
||||||
|
$table->string('city')->nullable();
|
||||||
|
$table->string('country')->nullable();
|
||||||
|
$table->enum('status', ['active', 'inactive', 'pending'])->default('active');
|
||||||
|
$table->text('notes')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('customers');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user