F
Filament3mo ago
Neamix

Pass params to a custom page

How can i create route as example chatroom/{room_id} and pass this room id to custom filament page
Solution:
You can use slug in custom page protected static ?string $slug = 'room/{id}'; public function mount($id): void...
Jump to solution
8 Replies
Tonkawuck
Tonkawuck3mo ago
Does your chatroom have a database record and laravel model? If so you can create a filament resource with a view page to do this. Generally the model is loaded into the record property on filament classes
LeandroFerreira
LeandroFerreira3mo ago
create a custom page: php artisan make:filament-page ChatRoom override this route in web.php
Route::get('/admin/chatroom/{room_id}',\App\Filament\Pages\ChatRoom::class);
Route::get('/admin/chatroom/{room_id}',\App\Filament\Pages\ChatRoom::class);
class ChatRoom extends Page
{
...
public ?int $room_id = null;

public function mount(): void
{
//You can access $this->room_id...
}
}
class ChatRoom extends Page
{
...
public ?int $room_id = null;

public function mount(): void
{
//You can access $this->room_id...
}
}
Neamix
NeamixOP3mo ago
I tried that but i found that the theme color that i choose has been return to default orange instead the one that i am using in panal
Route::get('admin/chatroom/{room_id}',ChatroomPage::class);

<?php

namespace App\Filament\Pages;

use App\Models\Chatroom;
use Filament\Pages\Page;

class ChatroomPage extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static string $view = 'filament.pages.chatroom-page';

public static function shouldRegisterNavigation(): bool
{
return false;
}

public function mount()
{
$chatroom = Chatroom::find(request()->room_id);
}
}
Route::get('admin/chatroom/{room_id}',ChatroomPage::class);

<?php

namespace App\Filament\Pages;

use App\Models\Chatroom;
use Filament\Pages\Page;

class ChatroomPage extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static string $view = 'filament.pages.chatroom-page';

public static function shouldRegisterNavigation(): bool
{
return false;
}

public function mount()
{
$chatroom = Chatroom::find(request()->room_id);
}
}
yes it has a modal but its not a resource as it wont fit the app logic
LeandroFerreira
LeandroFerreira3mo ago
is it another question?
Neamix
NeamixOP3mo ago
no its same question what i want to say i tried that solution and yea i have a page with a route params and that what i want but i am using primary color #51B78F but at this page it changed to the default Color::Orange of fiament
LeandroFerreira
LeandroFerreira3mo ago
I think this is another question.. anyway, you can customize the color in your appserviceprovider https://filamentphp.com/docs/3.x/support/colors#overview
Solution
jkbcoder
jkbcoder3mo ago
You can use slug in custom page protected static ?string $slug = 'room/{id}'; public function mount($id): void { dd($id); }
Neamix
NeamixOP3mo ago
this worked for me
Want results from more Discord servers?
Add your server