F
Filamentβ€’2mo 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β€’2mo 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β€’2mo ago
Filemant Pages are Livewire components so the same rules apply. You can use #[Computed] values. Or public properties
MZX
MZXβ€’2mo 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β€’2mo 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β€’2mo ago
That still overrides the render method πŸ˜…
toeknee
toekneeβ€’2mo ago
It returns the parent render so it doesn't replace it which is what I presume MZX means.
Dennis Koch
Dennis Kochβ€’2mo ago
But you can access public properties and methods and can add data via mount
toeknee
toekneeβ€’2mo ago
Ahaha of course, I heard render and stuck with it, I assumed for when he is re-rendering. But updated it anyway.
MZX
MZXβ€’2mo ago
it says method not found
toeknee
toekneeβ€’2mo ago
Where does it say that?
MZX
MZXβ€’2mo 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);
}