In Laravel 10/Filamentphp 3 multi tenancy app I added jeffgreco13/filament-breezy v2.2.1.1 package and added custom fields in app/Livewire/CustomProfileComponent.php, which I created with artisan command. Problem is that opening "/app/branch-name/my-profile" url my custom fields are not filled with data of current logged user with code like :
class CustomProfileComponent extends MyProfileComponent
{
protected string $view = "livewire.custom-profile-component";
public array $data;
public function form(Form $form): Form
{
$user = auth()->user();
\Log::info(varDump($user, ' -1 $user::'));
$employee = Employee::getByUserId($user->getAttribute('id'))->first();
return $form
->schema([
TextInput::make('name')
->required(),
Select::make('branch_id')->label('Branch')
->prefixIcon(BranchHelper::getIcon())
->preload()
->options(Branch::query()->pluck('name', 'id'))
//->default($user->getAttribute('branch_id'))
->required(),
])
->statePath('data');
Both 'name' and 'branch_id' fields are empty, even if I uncommented line with default method and valid data... Not sure what must be provided in statePath method ?
UPDATED BLOCK :
This CustomProfileComponent component has no $this->form var, but has $form var, which is passed as param to form method As my profile form consists of 2 tables : users employees I tried to use fill method :
<?php
class CustomProfileComponent extends MyProfileComponent
{
protected string $view = "livewire.custom-profile-component";
public array $data;
public function form(Form $form): Form
{
$user = auth()->user();
$this->data = $user->attributesToArray();
$employee = Employee::getByUserId($user->getAttribute('id'))->first();
\Log::info(varDump($employee, ' -1 $employee::'));
// $userAttributes = $user->attributesToArray();
if($employee) {
$this->data = Arr::collapse([$this->data, $employee->attributesToArray()]);
\Log::info(varDump($this->data, ' -1 $this->data::'));
// I check and see that array above has 'branch_id' key
}
$form->fill($this->data);
...
Any way Select component has no item selected...
What is wrong in my code ?
you have to use $this->form->fill($data);
like this example:
$this->data['branch_id'] = auth()->user()->branch_id;
$this->data['name'] = auth()->user()->name;
$this->data['email'] = auth()->user()->email;
$form->fill($this->data);