#Is Dashboard a livewire component?

63 messages · Page 1 of 1 (latest)

mental anvil
#

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,
        ]);
    }
}```
lofty yokeBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

sturdy atlas
#

Is you livewire view using the filament page component.?

mental anvil
sturdy atlas
#

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.

mental anvil
sturdy atlas
#

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.

mental anvil
sturdy atlas
#

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.

mental anvil
#

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

sturdy atlas
#

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.

mental anvil
sturdy atlas
#

Widgets don’t have state.?

mental anvil
# sturdy atlas Widgets don’t have state.?

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'),
        // ...
    ];
}
sturdy atlas
#

Forms have state

#

Sorry, my bad. Misread that.

mental anvil
sturdy atlas
#

But yea. Widgets have their own polling .

mental anvil
#

I understand, but do they only poll from getStats()?

sturdy atlas
#

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.

mental anvil
#

Should I have something to return?

<x-filament-widgets::widget>
    <x-filament::section>
        {{-- Widget content --}}
    </x-filament::section>
</x-filament-widgets::widget>
sturdy atlas
#

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.

mental anvil
#

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'),
        ];
    }
}
mental anvil
sturdy atlas
#

You’re doing too much. Music widget should be extending StatsWidget in this case.

#

Wait misread that too. Sorry.

mental anvil
sturdy atlas
#

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 .

mental anvil
#

Yes of course, but its not even rendering 😅

sturdy atlas
#

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.

mental anvil
sturdy atlas
#

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. 🙂

mental anvil
sturdy atlas
#

Hard to help sometimes without a more wholistic view sometimes.

mental anvil
#

Yeahh very understandable

#

Gimme a few

sturdy atlas
#

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.

mental anvil
#

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

sturdy atlas
#

Will look at it tomorrow. Getting late here. Hang in there. Will help soon.

mental anvil
#

Goodnight. Its 3am here 😅

sturdy atlas
mental anvil
#

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

sturdy atlas
#

Could be. It’s possible.

mental anvil
mental anvil
#

I got it working! Turns out mistakes were pretty easy to spot after a good night's sleep 😅