Laravel Flash或会话消息未到期[未维护更新] [英] Laravel flash or session messages not expiring [ not maintained Updated ]

查看:182
本文介绍了Laravel Flash或会话消息未到期[未维护更新]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过研究后已更新
经过一番研究,我得出的结论是,直到我明确保存会话后,我的会话才会被维护,下面的代码运行良好,但是为什么呢?

Updated after some research
After some research I conclude that, my sessions are not maintained until I save them explicitly, below code works well, but WHY???? Ref here

Session::put('lets_test', 2);
Session::save();

旧问题
我是laravel 5.3的新手,但遇到了问题.我的Laravel Session或Flash消息没有过期,每次重新加载页面时它们都会显示,直到我使用Session::flush()以下是我的控制器代码

Old Question
I'm new to laravel 5.3, and stuck at a problem. My Laravel Session or Flash messages are not expiring they display each time page is reloaded, until I use Session::flush() Below is my controller code

<?php

namespace App\Http\Controllers;


use Session;
use Auth;
use Illuminate\Http\Request;
use App\User;
use App\Hospital;
use App\Wpr;
use Helper;

class OperatorController extends Controller
{
    public $user_detail;

    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('operator');
    }
    public function store (Request $request){ //Form is being submitted here
        //My logic here
        Session::flash('user_message', 'Thank You');
        return redirect('/operator/wpr');
    }
}

我也用过Session::set('user_message', 4); 和刀片视图

@if(Session::has('user_message'))
    <div class="message  animated tada">
        {{ Session::get('user_message') }}
    </div>
@endif

我尝试过Session::forget('user_message'),但是没有运气. 经过研究后更新了我的帖子.通过在堆栈,因为此问题与我的问题完全相同,但不幸的是它仍然存在,因此,我已将会话存储从文件更改为数据库(以防万一文件具有存储目录​​权限).可能还有其他可能性吗?

I've tried with Session::forget('user_message') but no luck. Updating my post after some research. I've got somewhat close to my problem by reading this post on stack because this question is exactly same to my problem but unfortunately it still persists, I've changed my session storage from file to database (in case file permissions to storage directory). What might be other possibilities?

请帮助,谢谢.

推荐答案

最终,我设法以某种方式找到了解决我的问题的方法,即不维持会议.我认为这与文件许可无关.现在,我将显式保存会话并将其显式删除. 制作了一个Helper类,添加了两个方法

Ultimately, somehow, I managed to find solution for my problem, of not sustaining sessions. I don't think its any issue related to file permission. Now I'm saving my session explicitly and removing it explicitly. Made a Helper class added two methods

public static function SetMessage($message, $type){ 
   Session::put('user_message', $message);
   Session::put('user_message_type', $type);
   Session::save();
}
public static function ForgetMessage(){ 
   Session::forget('user_message');
   Session::forget('user_message_type');
   Session::save();
}

并在Controller类中

and within Controller class

 Helper::SetMessage('Record updated successfully', 'success');

并且在刀片视图模板中

@if(Session::has('user_message'))
    <div class="alert alert-{{ Session::get('user_message_type') }}">
     {{ Session::get('user_message') }}
     {{ Helper::ForgetMessage('user_message') }}
    </div>
@endif

我希望这会对遇到此类问题的人有所帮助. 为什么会这样,仍然未知,也许有一天我也会发布原因.如果可以通过更好的方式完成操作,欢迎提供更多建议.

I hope this might help someone who is facing such kind problem. But why is it so, still unknown, maybe one day I'll post the reason too. More suggestions are welcomed, if this could be done in a better way.

这篇关于Laravel Flash或会话消息未到期[未维护更新]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆