The laravel application url will be something like app.laravel.com\{clientName}
. All the routes will be following the client_name
, for example app.laravel.com\{clientName}\home
, app.laravel.com\{clientName}\profile
. Will load/ render the application depends on the clientName
.
routes/web.php
Route::group(['prefix' => '{clientName}', 'middleware' => 'appclient'], function () {
Route::get('/', 'ClientController@index');
Route::post('login', 'Auth\LoginController@login');
Route::post('logout', 'Auth\LoginController@logout');
Route::get('home', 'HomeController@index');
});
In the appclient
middleware
public function handle($request, Closure $next) {
$clientName = explode('/', $request->path())[0];
$client = Client::where('clientName', $clientName)->first();
if(!isset($client->id)) {
abort(404);
}
Config::set('session.path', "/$clientName");
return $next($request);
}
What I'm trying to achieve is set the session based on the clientName
directory. When I login I'm getting TokenMismatchException.
First question
Can I store the session based on url with directory like app.laravel.com\{clientName}
?
Second Question
I saw there is a setting session.path
, what above I tried is to use that approach. If that is possible, how can I fixed this issue? Is it a good idea to updating the session path in the middleware?
Appreciate any feed back or other approaches
UPDATE
Redis
as session driverWhat I did is updated the session.path
& session.cookie
dynamically.
Config::set('session.path', "$clientName");
Config::set('session.cookie', $clientName.'_laravel_session');
This is currently working for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With