F
Filamentβ€’3d ago
Glebka

How do I override getMaxContentWidth() globally?

Hi, I know about the ->maxContentWidth(MaxWidth::Full) method in an AdminPanelProvider, but it applies to every page. I need to apply it only to listRecords pages. Can I overwrite it for example in a AppServiceProvider?
Solution:
I believe Filament uses xx.index for list pages. You could create a custom middleware and use something like this ```php public function handle(Request $request, Closure $next): Response {...
Jump to solution
5 Replies
Solution
LeandroFerreira
LeandroFerreiraβ€’3d ago
I believe Filament uses xx.index for list pages. You could create a custom middleware and use something like this
public function handle(Request $request, Closure $next): Response
{
$currentPanel = filament()->getCurrentPanel();

if (str($request->route()->getAction('as'))->contains('index')) {
$currentPanel->maxContentWidth(MaxWidth::Full);
}

return $next($request);
}
public function handle(Request $request, Closure $next): Response
{
$currentPanel = filament()->getCurrentPanel();

if (str($request->route()->getAction('as'))->contains('index')) {
$currentPanel->maxContentWidth(MaxWidth::Full);
}

return $next($request);
}
$panel
...
->middleware([
...
CustomMiddleware::class
])
$panel
...
->middleware([
...
CustomMiddleware::class
])
LeandroFerreira
LeandroFerreiraβ€’3d ago
@Glebka did you try it in 1 minute? πŸ˜‚
Glebka
GlebkaOPβ€’3d ago
no, but you are one of a creators, no one knows filament beter than you. If you say that might work that means it will work i will test it now yes, thank you it worked
LeandroFerreira
LeandroFerreiraβ€’3d ago
I'm not the creator πŸ˜… This is just a suggestion, and there may be other ways to achieve it..
Glebka
GlebkaOPβ€’3d ago
oh, okey, but still thank you a lot!

Did you find this page helpful?