简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM