Laravel 5.4 在 Laravel Blade 中显示 Cookie 值

标签 laravel cookies laravel-5.4

如何通过插值或使用条件在 Laravel 5.4 Blade 中显示 Cookie 值?

有点像这样:

    @if (Cookie::get('user_first_name') !== null)
      <a href="javascript:;" id="user_name">
        <i class="fa fa-sign-in" aria-hidden="true"></i>{{ Cookie::get('user_first_name') }}
      </a>
    @else

最佳答案

您建议的方式是正确的:

{{ Cookie::get('user_first_name') }}

根据您的评论,您可能没有正确设置 cookie。您可以尝试:

Cookie::queue('user_first_name', 'John', 15);
return view('the-view');

关于Laravel 5.4 在 Laravel Blade 中显示 Cookie 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46618576/

相关文章:

php - Laravel 在字段中添加 30 分钟。示例 : $is_expired = $created_at + 30minutes;

mysql - 应删除注册页面中的自动登录

c# - 如何从 cookie 中检索 OpenID Connect 身份 token

python - 如何使用 Python Requests 库在 post 请求中发送 cookie?

cookies - 添加同站;安全到经典 ASP 中的 Cookie

javascript - 拉维 |如何在 JavaScript 中访问 session 数组?

mysql - 我有两个名为 created_at 和 updated_at(timestamps) 的字段,我想在我的 where 子句中的这些日期之间进行搜索

mongodb - Laravel MongoDB Jenssegers 如何获取文档的 "_id"

php - Laravel Socialite 扩展领域

Laravel - 如何在验证规则构造中自动注入(inject)?