Questions tagged [laravel-events]

Laravel's events provides a simple observer implementation, allowing you to subscribe and listen for events in your application.

Laravel's events provides a simple observer implementation, allowing you to subscribe and listen for events in your application.

Event classes are typically stored in the app/Events directory, while their listeners are stored in app/Listeners.

114 questions
3
votes
2 answers

Logout Event (Laravel 7)

I'm pretty new to Laravel and was wondering how I can set up a function to run on an event. Specifically, when a user log outs, how can I call a function? What would be the best way to do this, registering a new logout event or does Laravel 7…
GTS Joe
  • 3,612
  • 12
  • 52
  • 94
3
votes
3 answers

How to add custom event to a Laravel model

I have payment model and want to fire an custom event when payment confirmed. My model code:
Amin Shojaei
  • 5,451
  • 2
  • 38
  • 46
3
votes
1 answer

Understanding PHP event dispatching systems

I've never done anything event-driven in PHP, only Node.js, so I'm trying to understand how event dispatching systems work in PHP (such as Laravel events, CakePHP events and Symfony event dispatcher). This example is in the Laravel docs: protected…
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
3
votes
4 answers

Laravel-Event: How to use Auth::user() in a Event?

When I ask if(Auth::user()->role == "xxxx") inside CandidateEvent displays "Trying to get property of non-object" The problem is that component Auth::user() isn't working in my Event. What is the correct way to use Auth within Events? public…
2
votes
1 answer

How to pass the object from a listener of an event to another listener of the same event

In Laravel 9, I have created an Event called RegisterNewUserEvent with this __construct function ($data here holds the $request data of a form). public function __construct($data) { $this->data = $data; } And this event has two registered…
japose7523
  • 29
  • 2
  • 15
2
votes
2 answers

Laravel 5.8: Parameter passed to the event listener is getting null

I have created an Event called UserWalletNewTransaction.php and added this to it: public $transaction; public function __construct($transaction) { $this->$transaction = $transaction; } And also registered it at EventServiceProivder.php: use…
user16333885
2
votes
2 answers

Argument 3 passed to App\Events\NoticeAnnouncement::__construct() must be an instance of App\User

I am trying to send mail to all students when a notice will be posted by a teacher. For this, I am calling a event when the notice is being created, and passed notice,teacher and user through the event variable. But its giving a error saying that…
2
votes
0 answers

Creating a structure with Jobs, Events, Listeners, Queues in Laravel 8

I have a flow about that. I can solve the problem on paper. As a system admin, we have the following models: Clients, Departments, Users, Visitors, Calls, and Meetings. Clients are our customers. Departments are customers' departments. Users have…
2
votes
0 answers

Pusher private chat works on localhost, not working on live server

I have developed a chat system using laravel and Vue. Am using pusher for realtime communication. Everything works well on localhost. But on pushing to live server (shared hosting), the chat does not work. The error on pusher debug is: Cannot…
Anwar
  • 21
  • 3
2
votes
1 answer

Laravel listeners with queue doesn't execute

I am trying to make listeners work with a queue. Everything is set up correctly to connect to a Redis server. Event class BillingEvent extends BaseEvent { use Dispatchable, InteractsWithSockets, SerializesModels; private $event; …
Miljan Rakita
  • 1,433
  • 4
  • 23
  • 44
2
votes
2 answers

How do I create a Laravel global variable from session data and make available across all views?

I set session data on login in the LoginController like so: class LoginController extends Controller{ protected function authenticated($request, $user){ $record = ['name'=>'bob']; session(['profile' => $record]); } } The…
tgrass
  • 135
  • 3
  • 12
2
votes
2 answers

Laravel Update Eloquent Field automatically on save

I have a need to update a field in a database table to an MD5 hash of of the other field values (sting concat) I am trying to do this via the eloquent model saving/updating/creating events but it appears that you cannot use the events to…
Scott-David Jones
  • 292
  • 1
  • 6
  • 22
2
votes
2 answers

Laravel Listener not fired even though the event was triggered

I am developing a web application using Laravel framework. I am trying to trying to use event and listener in my application. But the event was trigged and the listener for the trigged event is not fired. This is my controller action public…
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372
2
votes
1 answer

Laravel 5.6 one event and many optional listeners

in Laravel 5.6 I have an event named DocumentSend, And i have many Listeners Like (SendEmail, SendNotification, SendSMS), listeners are optional (depends on document type and defined by user), now the question is: How can i call for example…
Hamed Yarandi
  • 1,085
  • 1
  • 12
  • 21
2
votes
1 answer

Laravel 5.3 Observer not triggering on updating event

I have created Observer for my model to update related data: getAttributes(); dd($data); …
Oleg Shakhov
  • 426
  • 6
  • 27