Why render a view on a sidebar in filament v3.2?

I need to render a view (or directly a widget 'account-widget') in a footer of a sidebar. But its not working. When I insert a string its work...

This is my code:

<?php

namespace App\Providers\Filament;

use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Widgets;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use Filament\Support\Facades\FilamentView;
use Filament\View\PanelsRenderHook;
use Illuminate\Contracts\View\View;


class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->default()
            ->brandLogo(asset('img/pax_life.png'))
            ->sidebarFullyCollapsibleOnDesktop()
            ->id('admin')
            ->path('admin')
            ->login()
            ->colors([
                'primary' => Color::Teal,
            ])
            ->renderHook(
                PanelsRenderHook::SIDEBAR_FOOTER,
                //fn (): View => view('filament.comp.account-user') // View not work
                fn (): string => ('USER LOGIN/LOGOUT') // work fine
            )
            ->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
            ->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
            ->pages([
                Pages\Dashboard::class,
            ])
            ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
            ->widgets([
                Widgets\AccountWidget::class,
                Widgets\FilamentInfoWidget::class, 
            ])
            ->middleware([
                EncryptCookies::class,
                AddQueuedCookiesToResponse::class,
                StartSession::class,
                AuthenticateSession::class,
                ShareErrorsFromSession::class,
                VerifyCsrfToken::class,
                SubstituteBindings::class,
                DisableBladeIconComponents::class,
                DispatchServingFilamentEvent::class,
            ])
            ->authMiddleware([
                Authenticate::class,
            ])
            ->plugins([
                \BezhanSalleh\FilamentShield\FilamentShieldPlugin::make()
            ]);
    }
}

The view 'filament.comp.account-user' is a simple TEST

This return a error: 'Using $this when not in object context'

I wanna try for a days and not find any help in a offical documentation...

please help-me...

Upvotes: -1

Views: 244

Answers (1)

MDSolanki
MDSolanki

Reputation: 20

  • If you just want to show widget you can do it.

-> just add desired widget to a blade file in your case filament.comp.account-user (you can create new blade file and add widget to that view) like show below :

<div>
    @livewire(\App\Filament\Widgets\UserChart::class)
</div>

-> Now just change your AdminPanelProvider code to this :

->renderHook(
    PanelsRenderHook::SIDEBAR_FOOTER,
    fn (): View => view('filament.comp.account-user')
)

-> this should do the work, let me now if any error occurs.

Upvotes: 0

Related Questions