When working with Laravel Fortify and wildcard subdomain routing, you need to ensure that all routes and responses are correctly handling the subdomain parameter. You've already managed to customize the password reset response, and now you need to do something similar for the password confirmation process.
Here's a step-by-step guide to address the issue with password confirmation:
-
Customize the Password Confirmation Response:
Similar to how you customized the password reset response, you need to create a custom response for password confirmation. Laravel Fortify uses the
PasswordConfirmedResponseinterface for this purpose.First, create a custom response class:
namespace App\Http\Responses; use Laravel\Fortify\Contracts\PasswordConfirmedResponse as PasswordConfirmedResponseContract; use Illuminate\Http\Request; class CustomPasswordConfirmedResponse implements PasswordConfirmedResponseContract { /** * Create an HTTP response that represents the object. * * @param \Illuminate\Http\Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function toResponse($request) { return redirect()->route('home', ['brand' => $request->brand]) ->with('status', 'Password confirmed successfully.'); } } -
Register the Custom Response in FortifyServiceProvider:
In your
FortifyServiceProvider, bind your custom response class to thePasswordConfirmedResponseinterface.use App\Http\Responses\CustomPasswordConfirmedResponse; use Laravel\Fortify\Contracts\PasswordConfirmedResponse; public function register() { $this->app->singleton(PasswordConfirmedResponse::class, CustomPasswordConfirmedResponse::class); } -
Ensure Routes Handle the Subdomain:
Make sure that your routes are set up to handle the
{brand}subdomain. For example:Route::domain('{brand}.my-website.test')->group(function () { Route::get('/home', [HomeController::class, 'index'])->name('home'); // Other routes... }); -
Pass the Subdomain Parameter:
When using the
route()helper, ensure that you pass thebrandparameter wherever necessary. This is crucial for maintaining the correct subdomain context.
By following these steps, you should be able to handle password confirmation with wildcard subdomains in Laravel Fortify. If you encounter any further issues, double-check that all routes and responses are correctly configured to handle the {brand} parameter.