F
Filament16mo ago
Scott

Add a notice to the top of a table page

I'd like to add a Shout (https://filamentphp.com/plugins/awcodes-shout) to the top of a resource page (i.e. a table listing), but this doesn't seem to be an option. Is there another way to achieve this? For example, in the screenshot attached, I'd like to show a notice above or below the "Airtable Accounts" heading
Filament
Shout by Adam Weston - Filament
A simple inline contextual notice for Filament Forms, basically just a fancy placeholder.
Solution:
In the end I did it as middleware on hte panel as I needed to do things based on the user's Auth status ```php ->authMiddleware([ Authenticate::class,...
Jump to solution
20 Replies
Dennis Koch
Dennis Koch16mo ago
You could add a table header widget instead with your own styling.
toeknee
toeknee16mo ago
So shout is only for forms, what you want to do is use a render hook 😉 Or Denis approach
awcodes
awcodes16mo ago
Not possible with the plugin at the moment. But it is planned now that widgets are configurable in v3.
Scott
ScottOP16mo ago
@toeknee_iom Thank you, hooks look like the solution. However, the documentation isn't clear where in a service provider the render hooks go. This is a common theme I'm finding wiht the docs, where it doesn't give an example in context :/
toeknee
toeknee16mo ago
Did you read: To register render hooks, you can call FilamentView::registerRenderHook() from a service provider or middleware.
Scott
ScottOP16mo ago
yep, but it doesnt say whether it goes in a boot function 🙂
toeknee
toeknee16mo ago
It doesn't, because it's a given 😉 but I see your point
Scott
ScottOP16mo ago
Still learning I suppose! I've tried doing this, but I get errors about the $scope
class AdminPanelProvider extends PanelProvider
{

public function boot()
{
FilamentView::registerRenderHook(
'panels::page.start',
fn (): \Illuminate\Contracts\View\View => view('subscription-notice'),
scopes: [
\App\Filament\Resources\SiteResource\Pages\ListSites::class,
\App\Filament\Resources\SiteResource\Pages\CreateSite::class,
\App\Filament\Resources\UserResource\Pages\EditSite::class,
],
);
}
}
class AdminPanelProvider extends PanelProvider
{

public function boot()
{
FilamentView::registerRenderHook(
'panels::page.start',
fn (): \Illuminate\Contracts\View\View => view('subscription-notice'),
scopes: [
\App\Filament\Resources\SiteResource\Pages\ListSites::class,
\App\Filament\Resources\SiteResource\Pages\CreateSite::class,
\App\Filament\Resources\UserResource\Pages\EditSite::class,
],
);
}
}
Error: Unknown named parameter $scopes Any ideas what I might be doing wrong?
toeknee
toeknee16mo ago
Are you on V3?
Scott
ScottOP16mo ago
yep
toeknee
toeknee16mo ago
Actually I don't
Scott
ScottOP16mo ago
lol I'm on a beta version, will try upgrading to the released v3
toeknee
toeknee16mo ago
Definitely upgrade also I think you can do this in the AdminPanelProvider.php as ->renderHook()
Scott
ScottOP16mo ago
oohhh, ok, cool - will take a look at that 🙂 thanks for your help!
toeknee
toeknee16mo ago
Not tested it, but theory on the PanelProvider.php (likely AdminPanelProvider.php):
->renderHook(
'panels::page.start',
fn (): View => view('warning-banner'),
scopes: [
\App\Filament\Resources\UserResource\Pages\CreateUser::class,
\App\Filament\Resources\UserResource\Pages\EditUser::class,
]
);
->renderHook(
'panels::page.start',
fn (): View => view('warning-banner'),
scopes: [
\App\Filament\Resources\UserResource\Pages\CreateUser::class,
\App\Filament\Resources\UserResource\Pages\EditUser::class,
]
);
Scott
ScottOP16mo ago
fab, thank you, will give it a go!
Solution
Scott
Scott16mo ago
In the end I did it as middleware on hte panel as I needed to do things based on the user's Auth status
->authMiddleware([
Authenticate::class,
RegisterSubscriptionNotice::class,
]);
->authMiddleware([
Authenticate::class,
RegisterSubscriptionNotice::class,
]);
Middleware
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Filament\Support\Facades\FilamentView;

class RegisterSubscriptionNotice
{
public function handle($request, Closure $next)
{

if (Auth::check()) {
$subscriptionData = [
'subscribed' => Auth::user()->currentTeam->subscribed(),
'trial_expired' => now()->greaterThanOrEqualTo(Auth::user()->currentTeam->trial_ends_at),
'team' => Auth::user()->currentTeam,
];

FilamentView::registerRenderHook(
'panels::content.start',
fn (): View => view('filament.hooks.subscription-notice', $subscriptionData)
);
}

return $next($request);
}
}
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Filament\Support\Facades\FilamentView;

class RegisterSubscriptionNotice
{
public function handle($request, Closure $next)
{

if (Auth::check()) {
$subscriptionData = [
'subscribed' => Auth::user()->currentTeam->subscribed(),
'trial_expired' => now()->greaterThanOrEqualTo(Auth::user()->currentTeam->trial_ends_at),
'team' => Auth::user()->currentTeam,
];

FilamentView::registerRenderHook(
'panels::content.start',
fn (): View => view('filament.hooks.subscription-notice', $subscriptionData)
);
}

return $next($request);
}
}
Scott
ScottOP16mo ago
Thanks again for all the help!
toeknee
toeknee16mo ago
Good work!
Want results from more Discord servers?
Add your server