maywz wrote a reply+100 XP
1mo ago
Just put it here. I found out that if we didn't redirect to the route that return inertia response. It'll throw us to the default route.
Here is my setup
File: app/Providers/FortifyServiceProvider.php
use Laravel\Fortify\Contracts\LoginResponse as LoginResponseContract;
use App\Http\Responses\LoginResponse;
/**
* Register any application services.
*/
public function register(): void
{
// Register LoginResponse as a singleton to prevent any binding
$this->app->singleton(LoginResponseContract::class, LoginResponse::class);
}
File: app/Http/Responses/LoginResponse.php
class LoginResponse implements LoginResponseContract
{
public function toResponse($request)
{
$user = $request->user();
if ($user->isCustomer()) return redirect()->route('customer.index');
return edirect()->route('admin.index');
}
}
File: app/Http/Controllers/CustomerController.php
public function index()
{
return Inertia::render('customer/index');
}
and the route file.
Route::get('/admin, function () {
// This controller or route must return as an Inertia response
return Inertia::render('admin/index');
})->name('admin.index');
Route::get('customer', [CustomerController::class, 'index'])->name('customer.index');
That's all, I hope it help.
maywz wrote a reply+100 XP
2mos ago