Reputation: 159
I have a logController
which has show()
method. In my show()
method, I am returning a single data that retrieved from the database.
$report = Log::select('logs.id')
->where('logs.id', '=', '1')
->get();
// event(new NewLog($report));
return $report;
In this case, the returning value is 1
. I am also expecting that data will be sent to Pusher will be the same as the result of the query. But the data that are being sent to Pusher are id, user_id
, date` etc. I just want to send the single data that I fetched which is logs.id.
Here is my NewLog Event:
class NewLog implements ShouldBroadcast
{
public $log;
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($log)
{
$this->log = $log;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('logs');
}
}
Upvotes: 1
Views: 787
Reputation: 1005
you can directly use the find() static function on Log. return $report will give you object.if you want to access the property of that object use as $report->property_name;
try using the below code:
$report = Log::find(1);
$event = event(new NewLog($report->id));
return $report->id;
OR
$report = Log::select('logs.id')
->where('logs.id', '=', '1')
->get();
// event(new NewLog($report->id));
return $report;
Upvotes: 1