0
將數據保存到數據庫後,我推送$message->user = Auth::user()->name
並返回$message
。它返回正確的對象。我只希望user
插入message
。將數據推入Laravel推送器中不工作的對象
{
"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;
}
}