Tell me how to pass the class to the method, with different arguments? Suppose if I overwrite the basic method of the model.

store($id) 

and add another argument there:

 store($id, OrderService $orderService) 

Everything works and I can work with the service inside the method, but if I create the method myself, let's say in the ProductService class:

 someMethod($id, OrderService $orderService) 

and when calling a function with a specific id, I get an error about the lack of arguments, how to solve this problem without creating a new class? how it works with the store method

    1 answer 1

    You need to understand that Lara injects dependencies only where it automatically creates objects. In the case of controller methods, this works, but if you create a class yourself, or call a method, you need to manually pass the required arguments.

    If you implement your service using a container, then use dependency injection through __construct(OrderService $orderService) , but if you need to get the instance of the required service only in the method, you can use

     $orderService = app(OrderService::class);