Questions tagged [laravel-ioc]

IoC (inversion of control) in Laravel

The Laravel inversion of control container is a powerful tool for managing class dependencies. Dependency injection is a method of removing hard-coded class dependencies. Instead, the dependencies are injected at run-time, allowing for greater flexibility as dependency implementations may be swapped easily.

Understanding the Laravel IoC container is essential to building a powerful, large application, as well as for contributing to the Laravel core itself.

Reference

9 questions
79
votes
15 answers

Laravel 5 - Interface is not instantiable

I know that this question was asked so many times, but none of answers helped me. I'm getting exception in Laravel 5 BindingResolutionException in Container.php line 785: Target [App\Contracts\CustomModelInterface] is not instantiable. What I've…
Andrew Kulakov
  • 2,064
  • 1
  • 16
  • 18
2
votes
2 answers

How do inject array of implementations into constructor in PHP

How do inject array of implementations into class through constructor. I am sharing the link which is c#. I want to achieve the same in php. How to achieve same in php. public interface IFoo { } public class FooA : IFoo {} public class FooB : IFoo…
user1844634
  • 1,221
  • 2
  • 17
  • 35
2
votes
2 answers

Overriding the log interface container binding lumen 5.0

I am trying to override where lumen writes logs, from 'storage/logs/lumen.log' to 'php://stderr'. The following code is what I am currently trying, and it does not work as expected. No errors are thrown, and my logs are still written to the default…
Robin
  • 1,395
  • 1
  • 9
  • 9
1
vote
0 answers

How to pass arguments from resolve() to callback specified in give()?

Constructor of class A requires an instance of class B, whose constructor in turn takes an optional string argument. I want to be able to specify the value of that string argument to class B constructor when resolving class A. I want to do something…
Szczepan Hołyszewski
  • 2,707
  • 2
  • 25
  • 39
0
votes
0 answers

How to provide multiple implementations for a class in Laravel?

We are using some geocoding to encode a few entries. Depending on some conditions we would like to switch from an implementation to another (different provider). Current service provider declaration: // some skipped and irrelevant imports class…
AsTeR
  • 7,247
  • 14
  • 60
  • 99
0
votes
1 answer

How to instantiate classes based on type in laravel?

So I have a BaseValuation abstract class and it's implementations example FooValuation and BarValuation. I want to instantiate Foo or Bar implementations depending on use input. So I created a simple class myself called Valuation which simply does…
Rohan
  • 13,308
  • 21
  • 81
  • 154
0
votes
1 answer

Laravel IoC doesn't automatically resolving the interface

I've just crossed this example, but it fails to resolve binding interface to implementation. Having the follow code files: // File: app/App/Services/Talkable.php
Pete Houston
  • 14,931
  • 6
  • 47
  • 60
0
votes
1 answer

Upload file error in lumen

I use laravelUploader package form this link for upload my files . when i use this package to send file in lumen with below code : $file = $this->uploader->file($request->file('file'))->push(storage_path('app')); return…
bitcodr
  • 1,395
  • 5
  • 21
  • 44
0
votes
1 answer

Injection in Repository

I found many questions about my problem and tried (I think) all the solutions, but I can not make it work. I'm overlooking something very easy, probably. I'm using Laravel 5. I try to implement a repository-pattern. I have an Eloquent model…
BakGat
  • 661
  • 2
  • 5
  • 19