I'm developing an application where the admin section is accessible via a subdomain like admin.mysite.test.
Everything works fine except sending emails with login credentials for users manually added by the administrator. The email is sent correctly and is visible with services like Mailtrap, but when redirecting after sending, a 404 is generated, and the debugbar reports that the 'admin.users.index' route doesn't exist. It seems like the reference to the subdomain is lost.
If I make the admin area accessible via mysite.test/admin instead of the subdomain, everything works.
I need the list of users entered in 'admin.users.index' to be reloaded after the email has been sent.
Any ideas?
Below is the resource method for inserting into the database.
/**
* Store a newly created resource in storage.
*/
public function store(UserFormRequest $request)
{
$user = new User($request->validated());
if ($file = $request->validated('image')) {
$path = $this->upload($file, $this->folder, $this->width, $this->height);
$user->image = $path;
}
$save = $user->save();
if ($save) {
$user->generated_password = $request->validated('password');
Mail::to($user->email)->send(new NewUserCreated($user));
return redirect()->route('admin.users.index')->with('success-message', 'Record inserito con successo.');
} else {
return back()->withInput()->with('error-message', 'Qualcosa è andato storto.');
}
}
route filke is:
use Illuminate\Support\Facades\Route;
Route::middleware('web')->domain('admin.' . env('SITE_URL'))->group( function () {
Auth::routes();
Route::group([
'as' => 'admin.',
'namespace' => 'App\Http\Controllers\Admin',
'middleware' => ['auth'],
], function () {
Route::get('dashboard', DashboardController::class)->name('dashboard');
//other routes...
Route::resource('users', App\Http\Controllers\Admin\UserController::class)
->except(['show']);
});
});
Route::group([
'as' => 'front.',
'namespace' => 'App\Http\Controllers\Front'
], function () {
Route::get('sitemap.xml', SitemapController::class)
->name('sitemap.xml');
});
// Localized
Route::localized(function () {
Route::group([
'as' => 'front.',
'namespace' => 'App\Http\Controllers\Front'
], function () {
Route::get(Lang::uri('home'), HomeController::class)
->name('home');
other routes...
});
});
.env file
APP_NAME="SMV"
APP_ENV=local
APP_DEBUG=true
APP_TIMEZONE=Europe/Rome
APP_URL=http://mysite.test
SITE_URL=mysite.test
APP_LOCALE=it
APP_FALLBACK_LOCALE=it
APP_FAKER_LOCALE=it_IT
APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database
PHP_CLI_SERVER_WORKERS=4
BCRYPT_ROUNDS=12
LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
SESSION_DRIVER=file
SESSION_EXPIRE_ON_CLOSE=true
SESSION_LIFETIME=120
SESSION_ENCRYPT=true
SESSION_PATH=/
SESSION_DOMAIN=.mysite.test
SESSION_HTTP_ONLY=true
SESSION_SAME_SITE=null
dd(redirect()->route('admin.users.index')->getTargetUrl())show?admin.mysite.test/users