-
How does this actually work? if not then how i can access my custom method like app()->test(), Is it possible? |
Beta Was this translation helpful? Give feedback.
Answered by
henzeb
Aug 30, 2023
Replies: 1 comment
-
That's not how it supposed to work. Maybe this example might illuminate things for you: class Hello {
public function say(string $something = null): void {
dump('Hello '.($something ?? 'space'));
}
}
(new Hello())->say();
(new Hello())->say('humans');
app()->bindMethod([Hello::class, 'say'], function (Hello $instance, $app) {
// Custom implementation for the process() method
return $instance->say('world');
});
if(app()->hasMethodBinding(Hello::class.'@say')) {
app()->callMethodBinding(Hello::class.'@say', new Hello());
} A reallife example in laravel would be: https://laravel.com/docs/10.x/queues#handle-method-dependency-injection It's used to override the dependency injection on methods at certain places. In the queue you can tell it to handle injection differently for certain jobs |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
aimonext
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's not how it supposed to work. Maybe this example might illuminate things for you:
A reallife example in laravel would be: https://laravel.com/docs/10.x/queues#handle-method-dependency-injection
It's used to override the …