如何解决laravel需要让用户使用多个凭据登录,这与使用其他帐户例如gmail登录相同,但使用一个活动用户
在我的项目中,不同用户的凭据应以Cookie的形式存储在同一浏览器中,并在用户需要时在帐户之间切换。感谢该用户回答了与我自己的问题类似的问题: Need to let users login with multiple credentials same as login with other account functionality in Gmail services- Laravel 我按照说明进行操作,并且在浏览器中一切都成功,但是在执行PHP artisan命令的同时在终端的config / session.php文件中使用了request()之后,发生以下错误
php artisan
在Container.php第811行中: 目标类别[要求]不存在。
在Container.php行809中: 类请求不存在
我的代码如下
config / session.php
<?php
$user_type = ( ( !empty(request()) && (int)request()->segment(2) ) > 0 ? '_'. request()->segment(2) : '');
return [
//.....rest of array
'cookie' => env(
'SESSION_COOKIE',Str::slug(env('APP_NAME','laravel'),'_').'_session'. $user_type //This user_type generate various session keys for your multiple login according to generated URL
),];
routes / web.php
/**
* Setting a variable to check if the user is logging in with first or multiple sessions
*/
$user_login = ( (int)request()->segment(2) > 0 ? 'u/'. request()->segment(2) : '' );
/**
* User attempting to login with other accounts
*/
Route::post($user_login. '/login','Auth\LoginController@login');
/**
* Get dashboard for filling the registeration forms
* Your entire app URL will now go like this,whether you can use it with user number or without it. It will go smoothly
*/
Route::get($user_login. '/dashboard',['as' => 'dashboard','uses' => 'FormController@getDashboard']);
/**
* User attempting to login with other accounts
*/
Route::post($user_login. '/logout','Auth\LoginController@logout');
另一个问题是,是否可以使用cookie来代替使用新路由来标识每个会话,并且仅允许存储在cookie中的凭据之一登录。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。