Saturday, August 13, 2016

Laravel 5.2 queuing Event listeners

First , we need to create Event and to listen event, we also have to create listener. To do this , laravel provides us several ways. The easiest way to create event and corresponding listener we can use this command
php artisan event:generate
To make it work, we have to define our event and corresponding listener in EventServiceProvider.php. So for test purpose lets provide following values in $listen variable.
'App\Events\DeleteBranchCourse' => [
            'App\Listeners\DeleteCourseConfirmation',
        ], 
Now we are ready to run our command
php artisan event:generate
So if we look carefully to Events and Listeners folders, we can see, DeleteBranchCourse and DeleteCourseConfirmation class created respectively. So to make listeners queue , we have to implement ShouldQueue and to manually configure queued jobs, we have to use InteractsWithQueue traits.
class DeleteCourseConfirmation implements ShouldQueue(){
  use InteractsWithQueue; 
}
So to use queue , we have to use database as queue driver. Now we will create a function hello in DeleteBranchCourse Event class and call this function from DeleteCourseConfirmation's handler function
public function handle(DeleteBranchCourse $event)
    {

        $this->attempts($event->hello());
    }
Now we have to fire our event from a controller's function
Event::fire(new DeleteBranchCourse($feeId));

Related Posts:

  • Install laravel 5.3 in Ubuntu 14.04 Once again Laravel comes with many amazing features and i can't wait more to try this all out. In this post i am going to write how to setup laravel 5.3 in Ubuntu 14.04. I am planning on making video for each of this … Read More
  • Laravel Elixir Setup and Uses Laravel Elixir provides a clean, fluent API for defining basic Gulp tasks for your Laravel application. Elixir supports several common CSS and JavaScript pre-processors, and even testing tools. Using method chaining, … Read More
  • Laravel Project Setup Using Composer In this tutorial i’ll write the key points that are necessary to create a laravel project/setting a laravel project with the help of composer. Composer Setup First We have to understand what is composer? Well, Composer is … Read More
  • Up & Running With Gulp Check Older version if installed $ npm rm --global gulp   Install Gulp Globally $ npm install --global gulp-cli Initializing Project directory npm init Installing Dependencies npm install --save-dev gulp Creatng gu… Read More
  • Api authorization with Passport in Laravel 5.3 This tutorial is basically an environment set up to understand how Passport works in Laravel 5.3. Passport is a way to manage authentication for accessing API in Laravel. It is very easy to implement and user do not need to… Read More

0 comments:

Post a Comment