mardi 26 juin 2018

Event not firing on model created Laravel.5.6

I want to fire an event on company created model. everything is fine in my check. but I don't know I am mistaking. the event is not firing at all.

Here is my Code.

EventServiceProvider.php

protected $listen = [
    'App\Events\NewCompany' => [
        'App\Listeners\SendWelcomeCompany',
    ],
];

Event NewCompany.php

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;
use App\Company;

class NewCompany
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

   public $company;
/**
 * Create a new event instance.
 *
 * @return void
 */
public function __construct(Company $company)
{
    $this->company = $company;
}

/**
 * Get the channels the event should broadcast on.
 *
 * @return \Illuminate\Broadcasting\Channel|array
 */
public function broadcastOn()
{
    return new PrivateChannel('channel-name');
}
}

Listener SendWelcomeCompany.php

    <?php

namespace App\Listeners;

use App\Events\NewCompany;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendWelcomeCompany
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  NewCompany  $event
     * @return void
     */
    public function handle(NewCompany $event)
    {
        Mail::to($event->company->email)->send(new NewCompanyWelcome($event->company));
    }
}

Company Model Company.php

namespace App;

use App\Events\NewCompany;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

protected $events = [
        'created' => NewCompany::class,
    ];

Please tell me what is it I am missing here?

Thanks



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2KqgSz6
via IFTTT

Aucun commentaire:

Enregistrer un commentaire