所以这可能很容易,但我已经好几个小时了。错误消息
Illuminate \ Container \ BindingResolutionException
Target [foo\repositories\OrderRepositoryInterface] is not instantiable.
我的界面:
<?php namespace foo\repositories;
interface OrderRepositoryInterface
{
public function index(array $dateRange = null, $customerId = null);
}
存储库:
<?php namespace foo\repositories;
use Carbon\Carbon;
use Order;
class OrderRepository implements OrderRepositoryInterface
{
public function index(array $dateRange = null, $customerId = null)
{
return 'HI';
}
}
我的路线档案:
App::bind('foo\repositories\OrderRepositoryInterface.php',
'foo\repositories\OrderRepository.php');
Route::resource('orders', 'OrdersController');
最后是控制器:
<?php
use foo\repositories\OrderRepositoryInterface;
class OrdersController extends \BaseController
{
protected $order;
/**
* @param OrderRepositoryInterface $order
*/
public function __construct(OrderRepositoryInterface $order)
{
$this->order = $order;
}
public function index()
{
$orders = $this->order->index();
return $orders;
}
答案 0 :(得分:1)
在App::bind
中绑定它们时,尝试从接口和存储库中删除.php
More about binding here
App::bind('foo\repositories\OrderRepositoryInterface',
'foo\repositories\OrderRepository');