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?
App\Forumthrows the error, but that isnt noted here.app->bind(the error shows up, here you have to dig in. Class declaration seems right. Or is something wrong with this statement:must implement interface Project\name\OrderInterfaceIs the namespace fully right?Orderable? -- forget this. You have to check the use of namespaces. Do check declared classes withvar_dump(get_declared_classes());at the end of a script.