{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/internals/issues/1000","repository_url":"https://api.github.com/repos/laravel/internals","labels_url":"https://api.github.com/repos/laravel/internals/issues/1000/labels{/name}","comments_url":"https://api.github.com/repos/laravel/internals/issues/1000/comments","events_url":"https://api.github.com/repos/laravel/internals/issues/1000/events","html_url":"https://github.com/laravel/internals/issues/1000","id":296694043,"number":1000,"title":"[Proposal] Dispatch eloquent collections","user":{"login":"alexbowers","id":842974,"avatar_url":"https://avatars1.githubusercontent.com/u/842974?v=4","gravatar_id":"","url":"https://api.github.com/users/alexbowers","html_url":"https://github.com/alexbowers","followers_url":"https://api.github.com/users/alexbowers/followers","following_url":"https://api.github.com/users/alexbowers/following{/other_user}","gists_url":"https://api.github.com/users/alexbowers/gists{/gist_id}","starred_url":"https://api.github.com/users/alexbowers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexbowers/subscriptions","organizations_url":"https://api.github.com/users/alexbowers/orgs","repos_url":"https://api.github.com/users/alexbowers/repos","events_url":"https://api.github.com/users/alexbowers/events{/privacy}","received_events_url":"https://api.github.com/users/alexbowers/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-13T10:54:38Z","updated_at":"2018-02-13T11:57:43Z","closed_at":null,"author_association":"NONE","body":"A fairly common part of my applications is to get a collection from Eloquent, and then to iterate over each of the records and dispatch a job with that record as the parameter:\r\n\r\nSomething like this:\r\n\r\n```php\r\n$customers = \\App\\Foundation\\Customer::live()->get();\r\n\r\n$customers->each(function ($customer) {\r\n    dispatch(new \\App\\Foundation\\Jobs\\SitemapGenerate($customer));\r\n});\r\n```\r\n\r\nI am proposing an alternative:\r\n\r\n```php\r\n$customers = \\App\\Foundation\\Customer::live()->get();\r\n\r\n$customers->dispatch(\\App\\Foundation\\Jobs\\SitemapGenerate::class);\r\n```\r\n\r\nWill automatically pass `customer` to the first parameter. If other parameters are required, i'd suggest going back to the existing method, or perhaps `dispatch` can accept multiple parameters to pass through?"},"comment":{"url":"https://api.github.com/repos/laravel/internals/issues/comments/365245983","html_url":"https://github.com/laravel/internals/issues/1000#issuecomment-365245983","issue_url":"https://api.github.com/repos/laravel/internals/issues/1000","id":365245983,"user":{"login":"Patryk27","id":3395477,"avatar_url":"https://avatars1.githubusercontent.com/u/3395477?v=4","gravatar_id":"","url":"https://api.github.com/users/Patryk27","html_url":"https://github.com/Patryk27","followers_url":"https://api.github.com/users/Patryk27/followers","following_url":"https://api.github.com/users/Patryk27/following{/other_user}","gists_url":"https://api.github.com/users/Patryk27/gists{/gist_id}","starred_url":"https://api.github.com/users/Patryk27/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Patryk27/subscriptions","organizations_url":"https://api.github.com/users/Patryk27/orgs","repos_url":"https://api.github.com/users/Patryk27/repos","events_url":"https://api.github.com/users/Patryk27/events{/privacy}","received_events_url":"https://api.github.com/users/Patryk27/received_events","type":"User","site_admin":false},"created_at":"2018-02-13T11:57:43Z","updated_at":"2018-02-13T11:57:43Z","author_association":"NONE","body":"Seems like breaking SRP - suddenly a regular collection would have a dependency on whole dispatching subsystem and that's too much IMHO.\r\n\r\nA helper method (like `dispatch_for_each($customers, MyEvent::class);`) could be provided though."}}
{"actor":{"display_login":"Patryk27"}}