feat: Implement Customer management with resource, pages, model, and migration for customer data handling
This commit is contained in:
parent
7c15781d5d
commit
557ae954d2
131
app/Filament/Resources/Master/Customers/CustomerResource.php
Normal file
131
app/Filament/Resources/Master/Customers/CustomerResource.php
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Master\Customers;
|
||||||
|
|
||||||
|
use App\Filament\Actions\Cheerful\DeleteAction;
|
||||||
|
use App\Filament\Actions\Cheerful\EditAction;
|
||||||
|
use App\Filament\Actions\Cheerful\ForceDeleteAction;
|
||||||
|
use App\Filament\Actions\Cheerful\RestoreAction;
|
||||||
|
use App\Filament\Actions\DefaultBulkActions;
|
||||||
|
use App\Filament\Columns\TimestampColumns;
|
||||||
|
use App\Filament\Resources\Master\Customers\Pages\ManageCustomers;
|
||||||
|
use App\Models\Customer;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Actions\BulkActionGroup;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Enums\Width;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Filters\TrashedFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
|
use UnitEnum;
|
||||||
|
|
||||||
|
class CustomerResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Customer::class;
|
||||||
|
|
||||||
|
protected static string|UnitEnum|null $navigationGroup = 'Master';
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::UserPlus;
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'Pelanggan';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 3;
|
||||||
|
|
||||||
|
protected static ?string $recordTitleAttribute = 'name';
|
||||||
|
|
||||||
|
protected static ?string $slug = 'master/customers';
|
||||||
|
|
||||||
|
public static function form(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->components([
|
||||||
|
TextInput::make('name')
|
||||||
|
->label('Nama')
|
||||||
|
->placeholder('John Doe')
|
||||||
|
->required()
|
||||||
|
->maxLength(100)
|
||||||
|
->autofocus()
|
||||||
|
->autocomplete(false),
|
||||||
|
|
||||||
|
TextInput::make('phone_number')
|
||||||
|
->label('Nomor HP')
|
||||||
|
->placeholder('08xxxxxxxxxx')
|
||||||
|
->required()
|
||||||
|
->maxLength(20)
|
||||||
|
->autocomplete(false),
|
||||||
|
|
||||||
|
TextInput::make('address')
|
||||||
|
->label('Alamat')
|
||||||
|
->placeholder('Jl. Raya No. 123, Jakarta Selatan')
|
||||||
|
->maxLength(255)
|
||||||
|
->autocomplete(false),
|
||||||
|
])
|
||||||
|
->columns(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('name')
|
||||||
|
->label('Nama')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
|
||||||
|
TextColumn::make('phone_number')
|
||||||
|
->label('Nomor HP')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
|
||||||
|
TextColumn::make('address')
|
||||||
|
->label('Alamat')
|
||||||
|
->limit(40)
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
|
||||||
|
...TimestampColumns::make(),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
TrashedFilter::make()
|
||||||
|
->native(false),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
EditAction::make()
|
||||||
|
->modalWidth(Width::Large),
|
||||||
|
|
||||||
|
DeleteAction::make(),
|
||||||
|
|
||||||
|
ForceDeleteAction::make(),
|
||||||
|
|
||||||
|
RestoreAction::make(),
|
||||||
|
])
|
||||||
|
->toolbarActions([
|
||||||
|
BulkActionGroup::make([
|
||||||
|
...DefaultBulkActions::make('Pelanggan'),
|
||||||
|
]),
|
||||||
|
])
|
||||||
|
->emptyStateIcon(Heroicon::UserPlus)
|
||||||
|
->emptyStateDescription('Setelah Anda membuat data pertama, maka akan muncul disini.')
|
||||||
|
->defaultSort('created_at', 'desc')
|
||||||
|
->deferFilters(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ManageCustomers::route('/'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRecordRouteBindingEloquentQuery(): Builder
|
||||||
|
{
|
||||||
|
return parent::getRecordRouteBindingEloquentQuery()
|
||||||
|
->withoutGlobalScopes([
|
||||||
|
SoftDeletingScope::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Master\Customers\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Actions\Cheerful\CreateAction;
|
||||||
|
use App\Filament\Resources\Master\Customers\CustomerResource;
|
||||||
|
use Filament\Resources\Pages\ManageRecords;
|
||||||
|
use Filament\Support\Enums\Width;
|
||||||
|
|
||||||
|
class ManageCustomers extends ManageRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = CustomerResource::class;
|
||||||
|
|
||||||
|
protected static ?string $title = 'Pelanggan';
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
CreateAction::make()
|
||||||
|
->label('Tambah')
|
||||||
|
->modalHeading('Tambah Pelanggan')
|
||||||
|
->modalSubmitActionLabel('Simpan')
|
||||||
|
->modalCancelActionLabel('Batal')
|
||||||
|
->extraModalFooterActions(fn (CreateAction $action): array => [
|
||||||
|
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
|
||||||
|
->label('Simpan dan Tambah Lagi'),
|
||||||
|
])
|
||||||
|
->modalWidth(Width::Large),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
14
app/Models/Customer.php
Normal file
14
app/Models/Customer.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class Customer extends Model
|
||||||
|
{
|
||||||
|
use HasFactory, SoftDeletes;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
<?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', 100);
|
||||||
|
$table->string('phone_number', 20);
|
||||||
|
$table->string('address')->nullable();
|
||||||
|
$table->timestamp('created_at')->useCurrent();
|
||||||
|
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
|
||||||
|
$table->softDeletes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('customers');
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user