【问题标题】:Laravel add and remove Auth session variablesLaravel 添加和删除 Auth 会话变量
【发布时间】:2015-05-25 06:01:44
【问题描述】:

用户登录系统后(Auth::attempt成功)

如何向身份验证会话添加额外数据并删除额外添加的变量
没有注销用户? (我的意思是不调用 Auth::logout();)

是否有 laravel 方法可以做到这一点?

更新:找到了添加的方法,但如何删除添加的变量?

Auth::user()->setAttribute('key','value');
//Auth::user()->unsetAttribute('key','value'); ????? how to remove
return Response::json(Auth::user());

【问题讨论】:

  • 我认为这不会起作用,因为您设置的属性不会在会话中持续存在
  • 在哪里添加这个 Auth::user()->setAttribute('key','value');代码工作

标签: laravel laravel-4 session-variables


【解决方案1】:

对此的简单回答,您可以使用 php 的 unset 函数取消设置变量、属性等。

试试这个

 unset(Auth::user()->key);

检查这个http://php.net/manual/en/function.unset.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-16
    • 2014-09-13
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-09
    • 1970-01-01
    相关资源
    最近更新 更多