将数据推送到Laravel Pusher中不起作用的对象

时间:2017-07-25 19:06:09

标签: laravel vue.js pusher

将数据保存到数据库后,我按$message->user = Auth::user()->name并返回$message。它返回正确的对象。我只是希望在user中插入message

{
  "message": {
    "id": 46,
    "channel": 1,
    "by": 1,
    "body": "saddla",
    "created_at": "2017-07-25 18:46:31",
    "updated_at": "2017-07-25 18:46:31",
    "user": "Clyde Santiago"
  }
}

但是当将$message传递给Pusher时,它只返回原始对象。不包括user。 以下是debug console

pusher中的数据
{
  "message": {
    "id": 46,
    "channel": 1,
    "by": 1,
    "body": "saddla",
    "created_at": "2017-07-25 18:46:31",
    "updated_at": "2017-07-25 18:46:31"
  }
}

这是我的MessageController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Message;
use Illuminate\Support\Facades\Auth;
use App\Events\Chat;

class MessageController extends Controller
{
    public function create(Request $request){
        $message = new Message;
        $message->channel = $request->channel_id;
        $message->by = Auth::user()->id;
        $message->body = $request->message;

        $message->save();
        $message->user = Auth::user()->name;
        event(new Chat($message));
        return $message;
    }
}

1 个答案:

答案 0 :(得分:0)

这个问题与Not sending the proper object data to Pusher重复 - 你有一些很好的答案:)