Reputation: 13
im trying to make notification system. I created Event:
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class DealApproved implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $username;
public $message;
public function __construct($username)
{
$this->username = $username;
$this->message = "{$username} approved your deal#50. Please take an action!";
}
public function broadcastOn()
{
return ['notification-channel-4'];
}
}
my route:
Route::get('/notify', 'NotificationController@approve_deal');
My controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Pusher\Pusher;
use Events\DealApproved;
class NotificationController extends Controller
{
public function approve_deal()
{
event(new App\Events\DealApproved('Someone'));
return "Event has been sent!";
}
}
when i use this route:
Route::get('notify', function () {
event(new App\Events\DealApproved('Someone'));
return "Event has been sent!";
});
everything works fine, but when i change route to controller i got error:
Class 'App\Http\Controllers\App\Events\DealApproved' not found
use Events\DealApproved; didnt work, please help
Upvotes: 0
Views: 545
Reputation: 2292
Just put this line in controller use App\Events\DealApproved;
and change this
event(new DealApproved('Someone'));
It should work.
Upvotes: 1