Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading Laravel 5.0 to Laravel 5.1 Commands to Jobs

Laravel 5.1 is renaming Commands to Jobs and Events to Listeners. http://laravel.com/docs/5.1/releases#laravel-5.1

I was using Commands and Command Handlers in Laravel 5.0 like so.

app\Commands\MyCommand

<?php namespace app\Commands;

use app\Commands\Command;

class MyCommand extends Command
{

    public $data;

    public function __construct($data)
    {
        $this->data = $data;
    }
}

app\Handlers\Commands\MyCommand

<?php namespace app\Handlers\Commands\Genapps;

use app\Commands\MyCommand;

class MyCommandHandler
{
    public function handle(MyCommand $command)
    {

    }
}

I don't see how I'm supposed to implement the handler in Laravel 5.1?

like image 436
user391986 Avatar asked Jun 10 '15 21:06

user391986


1 Answers

From the 5.1 release notes:

However, this is not a breaking change and you are not required to update to the new folder structure to use Laravel 5.1.

In case you want to upgrade, you just have to rename your folder and change the namespace (Laravel uses PSR-4 autoloader in version 5, so the folder structure corresponds to the namespace of your files).

However if your project is quite large I do not recommend you that, since as the documentation states this is not required step for the upgrade your code will work just fine in 5.1. It is more like a cosmetic change.

like image 146
Sh1d0w Avatar answered Oct 10 '22 16:10

Sh1d0w