This commit is contained in:
Konstantinos Arvanitakis
2026-07-01 18:35:39 +03:00
commit 9f58a36c82
44 changed files with 3848 additions and 0 deletions
@@ -0,0 +1,20 @@
<?php
namespace Modules\Core\Customer\Extensions;
use Lunar\Admin\Filament\Resources\CustomerResource\RelationManagers\AddressRelationManager as BaseAddressRelationManager;
use Lunar\Admin\Support\Extending\BaseExtension;
use Modules\Core\Customer\RelationManagers\AddressRelationManager;
class CustomerResourceExtension extends BaseExtension
{
public function getRelations(array $relations): array
{
return array_map(
fn ($relation) => $relation == BaseAddressRelationManager::class
? AddressRelationManager::class
: $relation,
$relations
);
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace Modules\Core\Customer\Models;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Foundation\Auth\Access\Authorizable;
class Customer extends \Lunar\Models\Customer implements AuthenticatableContract
{
use Authenticatable;
use Authorizable;
protected $casts = [
'otp_expires_at' => 'datetime',
];
public function getTitleAttribute(): ?string
{
return null;
}
public function setTitleAttribute($value): void
{
// title is not used
}
public function getFullNameAttribute(): string
{
return trim(
preg_replace(
"/\s+/",
" ",
"{$this->first_name} {$this->last_name}",
),
);
}
}
@@ -0,0 +1,97 @@
<?php
namespace Modules\Core\Customer\RelationManagers;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Tables\Actions\CreateAction;
use Filament\Tables\Actions\DeleteAction;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Lunar\Admin\Filament\Resources\CustomerResource\RelationManagers\AddressRelationManager as BaseAddressRelationManager;
use Lunar\Models\Contracts\Address as AddressContract;
class AddressRelationManager extends BaseAddressRelationManager
{
public function getDefaultTable(Table $table): Table
{
return $table
->heading(__('lunarpanel::address.plural_label'))
->columns([
TextColumn::make('line_one')->label(
__('lunarpanel::address.table.line_one.label')
),
TextColumn::make('city')->label(
__('lunarpanel::address.table.city.label')
),
TextColumn::make('postcode')->label(
__('lunarpanel::address.table.postcode.label')
),
TextColumn::make('contact_email')->label(
__('lunarpanel::address.table.contact_email.label')
),
TextColumn::make('contact_phone')->label(
__('lunarpanel::address.table.contact_phone.label')
),
])
->headerActions([
CreateAction::make()->form($this->addressForm()),
])
->actions([
EditAction::make('editAddress')
->fillForm(fn (AddressContract $record): array => [
'line_one' => $record->line_one,
'city' => $record->city,
'state' => $record->state,
'postcode' => $record->postcode,
'country_id' => $record->country_id,
'contact_email' => $record->contact_email,
'contact_phone' => $record->contact_phone,
])
->form($this->addressForm()),
DeleteAction::make('deleteAddress'),
]);
}
protected function addressForm(): array // phpcs:ignore
{
return [
TextInput::make('line_one')->label(
__('lunarpanel::address.form.line_one.label')
)->required(),
Group::make()->schema([
Select::make('country_id')->label(
__('lunarpanel::address.form.country_id.label')
)->relationship(
name: 'country',
)->getOptionLabelFromRecordUsing(function (Model $record) {
$name = $record->native ?: $record->name;
return "{$record->emoji} $name";
}),
TextInput::make('state')->label(
__('lunarpanel::address.form.state.label')
),
])->columns(2),
Group::make()->schema([
TextInput::make('city')->label(
__('lunarpanel::address.form.city.label')
)->required(),
TextInput::make('postcode')->label(
__('lunarpanel::address.form.postcode.label')
),
])->columns(2),
Group::make()->schema([
TextInput::make('contact_email')->label(
__('lunarpanel::address.form.contact_email.label')
),
TextInput::make('contact_phone')->label(
__('lunarpanel::address.form.contact_phone.label')
),
])->columns(2),
];
}
}