Routing issues

Hey all, I'm kind of new to using filament, and I would appreciate some help if possible. I am trying to build a dashboard panel for an admin but i want to use my own route not the preset one from filament.
7 Replies
kokpithua
kokpithuaOP13mo ago
Here is the route I want to use
Route::prefix('admin')->group(function () {
Route::get('dashboard/{id}', [UserController::class, 'showAdminDashboard'])->name('admin.dashboard');
});
Route::prefix('admin')->group(function () {
Route::get('dashboard/{id}', [UserController::class, 'showAdminDashboard'])->name('admin.dashboard');
});
Since i am currently using a user table and differentiating admins from a normal user i am using the user_type column Here is the UserController that handles this
//LoginForm
public function authenticate(Request $request) {
$credentials = $request->only('email', 'password');

if (Auth::attempt($credentials)) {
$user = Auth::user();
//Check user type
if ($user->user_type === 'admin') {
return redirect()->route('admin.dashboard', ['id' => $user->id])->with('message', 'You are now logged in!');//Admin login
} else {
return redirect()->route('user.dashboard', ['id' => $user->id])->with('message', 'You are now logged in!'); //User Login
}
}
return back()->withInput()->withErrors(['email' => 'Invalid email or password']);
}
//LoginForm
public function authenticate(Request $request) {
$credentials = $request->only('email', 'password');

if (Auth::attempt($credentials)) {
$user = Auth::user();
//Check user type
if ($user->user_type === 'admin') {
return redirect()->route('admin.dashboard', ['id' => $user->id])->with('message', 'You are now logged in!');//Admin login
} else {
return redirect()->route('user.dashboard', ['id' => $user->id])->with('message', 'You are now logged in!'); //User Login
}
}
return back()->withInput()->withErrors(['email' => 'Invalid email or password']);
}
Arko
Arko13mo ago
What are you exactly trying to do/solve? It sounds like you just want to have two different panels, one for admins and one for users, no?
kokpithua
kokpithuaOP13mo ago
Well I want to build the admin panel using filament. When I created the filament panel in my cmd it gave me a default route of admin. I want to change the route so whenever users with user_type = admin follow the admin.dashboard route.
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->colors
...
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->colors
...
I dont have any issues with the controller. I just want to change the path in the filament panel file. I don't know if you get the point i changed it in the provided file but it didn't work
Arko
Arko13mo ago
I just think that you're manually trying to solve something that you can solve with Filament natively
kokpithua
kokpithuaOP13mo ago
Any tips on how to do taht that*
Arko
Arko13mo ago
You can create two panels, and have them both have a separate path. One for users, one for admins https://filamentphp.com/docs/3.x/panels/configuration#the-default-admin-panel Then you can do the authorization (user_type = admin can only access the admin panel, etc) via the Users model: https://filamentphp.com/docs/3.x/panels/users#authorizing-access-to-the-panel
kokpithua
kokpithuaOP13mo ago
Alright. Thanks I appreciate it. I still seem to have some issues. Maybe I didn't make my point clear. So when i create a panel, it has a default path whether it be admin or whatever. In my routes i have a route which returns the admin/dashboard/{id} where id is the id of the user. What i want to do is take this route and return the view in my adminpanel provided by filament.
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin/dashboard/{id}')
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin/dashboard/{id}')
The usercontrollers function does not redirect me to the view contained within the adminpanel but instead to a blank blade file. Hopefully I made myself clearer this time
Want results from more Discord servers?
Add your server