如何保存session()值" "在laravel?

时间:2018-01-18 13:11:40

标签: laravel vue.js

app.js - > methods我有this.chat.image.push('');axios.post send我有

    methods:{
    send(){
        if(this.message.length != 0)
        {
            this.chat.message.push(this.message);
            this.chat.user.push('');
            this.chat.image.push('');
            this.chat.time.push('');
            axios.post('admin/send', {
                message : this.message,
                chat:this.chat
              })
              .then(response => {
                // console.log(response);

                this.message = '';
              })
        }    
    },
    getOldMessages(){
        axios.post('admin/getOldMessage')
              .then(response => {
                if (response.data != '') {
                    this.chat = response.data;
                }
              })
    },

mounted()我有

    mounted(){
    this.getOldMessages();
    Echo.channel('chat')
        .listen('ChatEvent', (e) => {
            this.chat.message.push(e.message);
            this.chat.user.push(e.user);               
         this.chat.image.push('source/admin/assets/images/avatar/'+e.image);
            axios.post('admin/saveToSession',{
                chat : this.chat
                .then(response => {
                    console.log(response);
                })
        })
    })
}

Controller我有函数saveToSession

    public function saveToSession(request $request)
    {
        session()->put('chat',$request->chat);
    }

send() function我得到image=" ";但是当我保存到会话时它返回null,为什么它返回值= " "?感谢

1 个答案:

答案 0 :(得分:0)

检查$ request->聊天中的值是否正常,如果是,那么您也可以尝试其他方法

通过请求实例

$ request-> session() - > put('key','value');

通过全球帮助

session(['key'=>'value']);

相关问题