F
Filamentβ€’8mo ago
MZX

How to pass data into a filament page?

How do I pass data in the render function without overriding the main one.
11 Replies
toeknee
toekneeβ€’8mo ago
Is this for your quiz? just use a filament form and a view field tbh... But it all depends on where the data is from etc
Dennis Koch
Dennis Kochβ€’8mo ago
Filemant Pages are Livewire components so the same rules apply. You can use #[Computed] values. Or public properties
MZX
MZXOPβ€’8mo ago
this is one of my livewire components render function
public function render()
{
return view('livewire.home', [
'quizzes' => Quiz::all(),
]);
}
public function render()
{
return view('livewire.home', [
'quizzes' => Quiz::all(),
]);
}
how would i do the same in a filament page without overriding the base render function?
toeknee
toekneeβ€’8mo ago
public array $quizzes;

public function mount() {

parent::mount();
$this->quizzes = Quiz::all();

}
public array $quizzes;

public function mount() {

parent::mount();
$this->quizzes = Quiz::all();

}
Something like that?
Dennis Koch
Dennis Kochβ€’8mo ago
That still overrides the render method πŸ˜…
toeknee
toekneeβ€’8mo ago
It returns the parent render so it doesn't replace it which is what I presume MZX means.
Dennis Koch
Dennis Kochβ€’8mo ago
But you can access public properties and methods and can add data via mount
toeknee
toekneeβ€’8mo ago
Ahaha of course, I heard render and stuck with it, I assumed for when he is re-rendering. But updated it anyway.
MZX
MZXOPβ€’7mo ago
it says method not found
toeknee
toekneeβ€’7mo ago
Where does it say that?
MZX
MZXOPβ€’7mo ago
i actually managed to make it work. Just the standard mounting worked. I actually had another issue with the scope. If anyone comes across this, if you want to pass something in the render function of a filament page, this is how you do it.
public function render(): View
{
$data = [
'currentQuestion' => $this->questions[$this->currentQuestionIndex],
]; //the data you wanna pass

return parent::render()->with($data);
}
public function render(): View
{
$data = [
'currentQuestion' => $this->questions[$this->currentQuestionIndex],
]; //the data you wanna pass

return parent::render()->with($data);
}
Want results from more Discord servers?
Add your server