Skip to content

Commit d17e701

Browse files
committed
document bindMethod
1 parent 885ed0b commit d17e701

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

queues.md

+8
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ In this example, note that we were able to pass an [Eloquent model](/docs/{{vers
164164

165165
The `handle` method is called when the job is processed by the queue. Note that we are able to type-hint dependencies on the `handle` method of the job. The Laravel [service container](/docs/{{version}}/container) automatically injects these dependencies.
166166

167+
If you would like to take total control over how the container injects dependencies into the `handle` method, you may use the container's `bindMethod` method. The `bindMethod` method accepts a callback which receives the job and the container. Within the callback, you are free to invoke the `handle` method however you wish. Typically, you should call this method from a [service provider](/docs/{{version}}/providers):
168+
169+
use App\Jobs\ProcessPodcast;
170+
171+
$this->app->bindMethod(ProcessPodcast::class.'@handle', function ($job, $app) {
172+
return $job->handle($app->make(AudioProcessor::class));
173+
});
174+
167175
> {note} Binary data, such as raw image contents, should be passed through the `base64_encode` function before being passed to a queued job. Otherwise, the job may not properly serialize to JSON when being placed on the queue.
168176
169177
<a name="dispatching-jobs"></a>

0 commit comments

Comments
 (0)