{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/7921","labels_url":"https://api.github.com/repos/laravel/framework/issues/7921/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/7921/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/7921/events","html_url":"https://github.com/laravel/framework/pull/7921","id":60271854,"number":7921,"title":"[5.0] Allow constructorless commands","user":{"login":"antonioribeiro","id":3182864,"avatar_url":"https://avatars.githubusercontent.com/u/3182864?v=3","gravatar_id":"","url":"https://api.github.com/users/antonioribeiro","html_url":"https://github.com/antonioribeiro","followers_url":"https://api.github.com/users/antonioribeiro/followers","following_url":"https://api.github.com/users/antonioribeiro/following{/other_user}","gists_url":"https://api.github.com/users/antonioribeiro/gists{/gist_id}","starred_url":"https://api.github.com/users/antonioribeiro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antonioribeiro/subscriptions","organizations_url":"https://api.github.com/users/antonioribeiro/orgs","repos_url":"https://api.github.com/users/antonioribeiro/repos","events_url":"https://api.github.com/users/antonioribeiro/events{/privacy}","received_events_url":"https://api.github.com/users/antonioribeiro/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/laravel/framework/labels/low%20priority","name":"low priority","color":"bfe5bf"},{"url":"https://api.github.com/repos/laravel/framework/labels/proposal","name":"proposal","color":"d4c5f9"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-08T19:27:35Z","updated_at":"2015-03-09T00:38:53Z","closed_at":"2015-03-08T23:21:27Z","pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/7921","html_url":"https://github.com/laravel/framework/pull/7921","diff_url":"https://github.com/laravel/framework/pull/7921.diff","patch_url":"https://github.com/laravel/framework/pull/7921.patch"},"body":"If we don't have anything else to do in a command constructor than set the object properties, we could just write\r\n\r\n```\r\nclass PurchasePodcast extends Command implements SelfHandling {\r\n\r\n    public $user, $podcast;\r\n\r\n    /**\r\n     * Execute the command.\r\n     *\r\n     * @return void\r\n     */\r\n    public function handle()\r\n    {\r\n        // Handle the logic to purchase the podcast...\r\n\r\n        event(new PodcastWasPurchased($this->user, $this->podcast));\r\n    }\r\n\r\n}\r\n```\r\n\r\nInstead of \r\n\r\n```\r\nclass PurchasePodcast extends Command implements SelfHandling {\r\n\r\n    protected $user, $podcast;\r\n\r\n    /**\r\n     * Create a new command instance.\r\n     *\r\n     * @return void\r\n     */\r\n    public function __construct(User $user, Podcast $podcast)\r\n    {\r\n        $this->user = $user;\r\n        $this->podcast = $podcast;\r\n    }\r\n\r\n    /**\r\n     * Execute the command.\r\n     *\r\n     * @return void\r\n     */\r\n    public function handle()\r\n    {\r\n        // Handle the logic to purchase the podcast...\r\n\r\n        event(new PodcastWasPurchased($this->user, $this->podcast));\r\n    }\r\n\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/77785112","html_url":"https://github.com/laravel/framework/pull/7921#issuecomment-77785112","issue_url":"https://api.github.com/repos/laravel/framework/issues/7921","id":77785112,"user":{"login":"antonioribeiro","id":3182864,"avatar_url":"https://avatars.githubusercontent.com/u/3182864?v=3","gravatar_id":"","url":"https://api.github.com/users/antonioribeiro","html_url":"https://github.com/antonioribeiro","followers_url":"https://api.github.com/users/antonioribeiro/followers","following_url":"https://api.github.com/users/antonioribeiro/following{/other_user}","gists_url":"https://api.github.com/users/antonioribeiro/gists{/gist_id}","starred_url":"https://api.github.com/users/antonioribeiro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antonioribeiro/subscriptions","organizations_url":"https://api.github.com/users/antonioribeiro/orgs","repos_url":"https://api.github.com/users/antonioribeiro/repos","events_url":"https://api.github.com/users/antonioribeiro/events{/privacy}","received_events_url":"https://api.github.com/users/antonioribeiro/received_events","type":"User","site_admin":false},"created_at":"2015-03-09T00:38:53Z","updated_at":"2015-03-09T00:38:53Z","body":"I'm not removing the process, I'm adding functionality to it. It first checks if the constructor is present and uses it, but falls back to the class public properties in case the coder has decided to not create a constructor.\r\n\r\nProperties are set by name, if your request and command have the very same input/property name, that command property will receive the value of the input. It is already like that, the difference is that currently it uses the constructor parameters names, instead of the properties directly."}}