F
Filament16mo ago
lodeki

Using $this when not in object context

Folllowed exactly this to add form to a livewire component but faces the above error. https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component. Tried the suggestions in the #form-builder but still facing the same issue.
15 Replies
Dennis Koch
Dennis Koch16mo ago
Share you component class and Blade view
lodeki
lodekiOP16mo ago
<?php

namespace App\Livewire;

use Filament\Forms\Components\Fieldset;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Livewire\Component;

class Biodata extends Component implements HasForms
{

use InteractsWithForms;

public ?array $data = [];

public function mount(): void
{
$this->form->fill();
}



public function form(Form $form): Form
{
return $form->schema([
Fieldset::make()->schema([
Radio::make('type')->options(['agent' => 'Agent', 'manager' => 'Manager'])->required()->reactive(),
TextInput::make('commision')->visible(fn ($get) => $get('type') == 'agent' ? true : false),
]),
])->statePath('data');
}

public function create(): void
{
dd($this->form->getState());
}
}
<?php

namespace App\Livewire;

use Filament\Forms\Components\Fieldset;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Livewire\Component;

class Biodata extends Component implements HasForms
{

use InteractsWithForms;

public ?array $data = [];

public function mount(): void
{
$this->form->fill();
}



public function form(Form $form): Form
{
return $form->schema([
Fieldset::make()->schema([
Radio::make('type')->options(['agent' => 'Agent', 'manager' => 'Manager'])->required()->reactive(),
TextInput::make('commision')->visible(fn ($get) => $get('type') == 'agent' ? true : false),
]),
])->statePath('data');
}

public function create(): void
{
dd($this->form->getState());
}
}
and the blade view
<div>
{{ $this->form }}
<button type="submit">Submit</button>
</div>
<div>
{{ $this->form }}
<button type="submit">Submit</button>
</div>
Dennis Koch
Dennis Koch16mo ago
Can you please share the stack trace as mentioned in #✅┊rules
lodeki
lodekiOP16mo ago
Flare
Using $this when not in object context - The error occurred at http://localhost:8000/manager
LeandroFerreira
LeandroFerreira16mo ago
Did you create the component using the artisan command? https://livewire.laravel.com/docs/components#creating-components Where is the render method?
Laravel
Components | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
lodeki
lodekiOP16mo ago
Yes I did create with the artisan command ....It was there but i removed it . It still works using the livewire underlying render() method.
LeandroFerreira
LeandroFerreira16mo ago
where are you using this component?
lodeki
lodekiOP16mo ago
On the dashboard inside a tour .
LeandroFerreira
LeandroFerreira16mo ago
how are you including? Can you share the code please?
lodeki
lodekiOP16mo ago
Tour::make('dashboard')
->steps(
Step::make()
->title('Welcome to Kodibooks !')->description('Your one stop solution for tenant management !.Lets get some walkthroughs to get you started')
->icon('heroicon-s-cake')->iconColor('primary')->uncloseable(),
Step::make('.fi-avatar')
->title('Account ')
->description(view('livewire.biodata'))
->icon('heroicon-s-user-circle')->iconColor('primary')->uncloseable()
)
Tour::make('dashboard')
->steps(
Step::make()
->title('Welcome to Kodibooks !')->description('Your one stop solution for tenant management !.Lets get some walkthroughs to get you started')
->icon('heroicon-s-cake')->iconColor('primary')->uncloseable(),
Step::make('.fi-avatar')
->title('Account ')
->description(view('livewire.biodata'))
->icon('heroicon-s-user-circle')->iconColor('primary')->uncloseable()
)
.
LeandroFerreira
LeandroFerreira16mo ago
why aren't you using this form inside step schema ?
lodeki
lodekiOP16mo ago
Wanted to get some user information as they go through the onboarding.
LeandroFerreira
LeandroFerreira16mo ago
I think you can't add this component in the description.. IMO you should add the fields in your form..
Dennis Koch
Dennis Koch16mo ago
You are trying to mount a form inside a form in a description? 🤯
lodeki
lodekiOP16mo ago
The step isn't really a form.
Want results from more Discord servers?
Add your server