I'm using Laravel 5.4
And I'm trying to inject a $order
class into a trait
that's going to implemented by a model
. Like this:
class Forum extends Model
{
use Orderable;
The constructor
of the trait looks like this:
trait Orderable
{
public $orderInfo;
public function __construct(OrderInterface $orderInfo)
{
$this->orderInfo = $orderInfo;
}
My service provider looks like this:
public function register()
{
$this->app->bind(OrderInterface::class, function () {
return new Order(new OrderRepository());
});
$this->app->bind(OrderRepositoryInterface::class, function () {
return new OrderRepository();
});
}
The constructor of my Order
class looks like this:
public function __construct(OrderRepositoryInterface $orderInfo)
{
$this->orderInfo = $orderInfo;
}
But I receive the error:
Type error: Argument 1 passed to App\Forum::__construct() must implement interface Project\name\OrderInterface, array given, called in /home/vagrant/Code/Package/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 268
The OrderRepository
class is implementing the OrderRepositoryInterface
. The Order class is implementing the OrderInterface
interface.
App\Forum is the model that uses the Orderable
trait.
What could I be doing wrong here?
via Jenssen