Is Dashboard a livewire component?

Dashboard is a Page, right? Which means its a livewire component. Why cant I pass values to the blade file?
<?php

namespace App\Filament\Pages;

use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Contracts\HasForms;
use Filament\Pages\Page;
use Filament\Pages\Dashboard as FilamentDashboard;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Action;
use Http;
use Illuminate\Http\Client\Response;
use Illuminate\Contracts\View\View;

class Dashboard extends FilamentDashboard implements HasForms, HasActions
{
use InteractsWithActions;
use InteractsWithForms;

protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static string $view = 'filament.pages.dashboard';

public function testAction(): Action
{
return Action::make('test')
->button();
}

public function render(): View
{
return view('filament.pages.dashboard', [
'users' => 10,
]);
}
}
<?php

namespace App\Filament\Pages;

use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Contracts\HasForms;
use Filament\Pages\Page;
use Filament\Pages\Dashboard as FilamentDashboard;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Action;
use Http;
use Illuminate\Http\Client\Response;
use Illuminate\Contracts\View\View;

class Dashboard extends FilamentDashboard implements HasForms, HasActions
{
use InteractsWithActions;
use InteractsWithForms;

protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static string $view = 'filament.pages.dashboard';

public function testAction(): Action
{
return Action::make('test')
->button();
}

public function render(): View
{
return view('filament.pages.dashboard', [
'users' => 10,
]);
}
}
No description
40 Replies
awcodes
awcodes15mo ago
Is you livewire view using the filament page component.?
DarkKnight
DarkKnightOP15mo ago
yes its is!
<x-filament-panels::page>
// ...
<x-filament::section>
<div @click="test">
{{$this->testAction}}

<x-filament-actions::modals />
</div>

<span>{{$this->users}}</span>
</x-filament::section>
</div>
</x-filament-panels::page>
<x-filament-panels::page>
// ...
<x-filament::section>
<div @click="test">
{{$this->testAction}}

<x-filament-actions::modals />
</div>

<span>{{$this->users}}</span>
</x-filament::section>
</div>
</x-filament-panels::page>
awcodes
awcodes15mo ago
Better question why are you defining a view property and a render method? Livewire doesn’t know what to do They are part of the same thing and you’re just confusing it.
DarkKnight
DarkKnightOP15mo ago
Because I went to the BasePage and that render() had defined a View property
No description
No description
awcodes
awcodes15mo ago
Yea but your overriding it. You don’t need to do that. The view property says to render that view. But then you’re telling it to ignore you view property and try to render a different view that it can’t find. Use one or the other, not both.
DarkKnight
DarkKnightOP15mo ago
So I should just keep it like this?
public function render()
{
return view('filament.pages.dashboard', [
'users' => 10,
]);
}
public function render()
{
return view('filament.pages.dashboard', [
'users' => 10,
]);
}
awcodes
awcodes15mo ago
If you make users a property on the livewire component then you don’t have to pass it. But I can’t recommend one or the other without understanding the actual use case. Neither are wrong. It depends on the use case and what should be exposed publicly. But you can’t use both methodologies at the same time.
DarkKnight
DarkKnightOP15mo ago
Basically what I want to do is fetch some data periodically (like every 2s) and display it on the widget. Like a function that will run every 2s and output something
awcodes
awcodes15mo ago
Widgets have a polling setting. They are their own livewire components. Sounds like you need to focus on the widget and less on the page.
DarkKnight
DarkKnightOP15mo ago
is polling only done for the getStats() function?
awcodes
awcodes15mo ago
Widgets don’t have state.?
DarkKnight
DarkKnightOP15mo ago
not state, getStats()
protected function getStats(): array
{
return [
Stat::make('Unique views', '192.1k')
->description('32k increase')
->descriptionIcon('heroicon-m-arrow-trending-up')
->chart([7, 2, 10, 3, 15, 4, 17])
->color('success'),
// ...
];
}
protected function getStats(): array
{
return [
Stat::make('Unique views', '192.1k')
->description('32k increase')
->descriptionIcon('heroicon-m-arrow-trending-up')
->chart([7, 2, 10, 3, 15, 4, 17])
->color('success'),
// ...
];
}
awcodes
awcodes15mo ago
Forms have state Sorry, my bad. Misread that.
DarkKnight
DarkKnightOP15mo ago
Haha, no problem
awcodes
awcodes15mo ago
But yea. Widgets have their own polling .
DarkKnight
DarkKnightOP15mo ago
I understand, but do they only poll from getStats()?
awcodes
awcodes15mo ago
When you poll the widget will re-evaluate itself. They don’t poll from getStats. Polling tells live wire to rerun the component meaning getStats will get processed on each polling interval and dom diffed to the widget. In livewire, polling basically refreshes the livewire component.
DarkKnight
DarkKnightOP15mo ago
Should I have something to return?
<x-filament-widgets::widget>
<x-filament::section>
{{-- Widget content --}}
</x-filament::section>
</x-filament-widgets::widget>
<x-filament-widgets::widget>
<x-filament::section>
{{-- Widget content --}}
</x-filament::section>
</x-filament-widgets::widget>
Understandable
awcodes
awcodes15mo ago
Not to say there may or may not be caveats in that depending on the hydration lifecycle of the component but that boils down to your understanding of livewire and how to apply it’s lifecycle hooks. But in this case Stats should respect the polling lifecycle and re-render appropriately without you needing to intervene.
DarkKnight
DarkKnightOP15mo ago
As it is now, the doesnt show anything
<?php

namespace App\Filament\Widgets;

use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Filament\Widgets\Widget;
use Illuminate\Contracts\View\View;

class MusicWidget extends BaseWidget
{
protected static string $view = 'filament.widgets.music-widget';

protected function getStats(): array
{
return [
Stat::make('Unique views', '192.1k'),
];
}
}
<?php

namespace App\Filament\Widgets;

use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Filament\Widgets\Widget;
use Illuminate\Contracts\View\View;

class MusicWidget extends BaseWidget
{
protected static string $view = 'filament.widgets.music-widget';

protected function getStats(): array
{
return [
Stat::make('Unique views', '192.1k'),
];
}
}
Yeah Im still trying very hard to understand how livewire works.
awcodes
awcodes15mo ago
You’re doing too much. Music widget should be extending StatsWidget in this case. Wait misread that too. Sorry.
DarkKnight
DarkKnightOP15mo ago
But docs do the same
No description
DarkKnight
DarkKnightOP15mo ago
Ah oke
awcodes
awcodes15mo ago
Only thing standing out to me in that code is that your returning a hard coded value to the Stat. So it’ll never change .
DarkKnight
DarkKnightOP15mo ago
Yes of course, but its not even rendering 😅
No description
awcodes
awcodes15mo ago
Can you share a repo. Feel like something might be off at a higher level. Feel free to DM me if you don’t want to share it publicly.
DarkKnight
DarkKnightOP15mo ago
Sure. But the repo is private haha
awcodes
awcodes15mo ago
You can add me and then delete me after the issue is resolved. I won’t be mad lol. Just trying to help, but it’s your call. 🙂
DarkKnight
DarkKnightOP15mo ago
yaah I know. In my mind I didnt know if you were going to be ok with sharing your email so I can add you but then I remembered that you have your own public repos 🤣
awcodes
awcodes15mo ago
Hard to help sometimes without a more wholistic view sometimes.
DarkKnight
DarkKnightOP15mo ago
Yeahh very understandable Gimme a few
awcodes
awcodes15mo ago
I’m a visual learner. Lol. If it’s private you can just add me as a contributor with my GitHub username. I’m really good at debugging. Not so great at guessing.
DarkKnight
DarkKnightOP15mo ago
How can I invite you sir? I cant find you by adamweston ah its just awcodes. Im just overcomplicating it I have sent you an invite
awcodes
awcodes15mo ago
Will look at it tomorrow. Getting late here. Hang in there. Will help soon.
DarkKnight
DarkKnightOP15mo ago
Understandable. Thank you:) Goodnight. Its 3am here 😅
awcodes
awcodes15mo ago
Ugh. Go to sleep. It’s 9:25 here. Also known as clock out. We’ll get it resolved. Just not tonight. Have a good one.
DarkKnight
DarkKnightOP15mo ago
I created a new project and I have the same issue. There might be a small chance that there is something going on with filament-widgets, but will have a look tomorrow as well
awcodes
awcodes15mo ago
Could be. It’s possible.
DarkKnight
DarkKnightOP15mo ago
Could it be that Im specifying a view path? Im pretty sure the path is the the blade file is correct. But in the docs there is no $viewIts just using the default view. I got it working! Turns out mistakes were pretty easy to spot after a good night's sleep 😅
Want results from more Discord servers?
Add your server