我正在使用Laravel 9,我有一个这样的控制器:
use App\Repositories\HomeRepositoryInterface;
class HomeController extends Controller
{
private $homeRespository;
public function __construct(HomeRepositoryInterface $homeRepository)
{
$this->homeRespository = $homeRepository;
}
...
以下是前HomeRepositoryInterface
名:
<?php
namespace App\Repositories;
interface HomeRepositoryInterface
{
public function newest();
}
这就是HomeRepository
强本身:
<?php
namespace App\Repositories;
use App\Models\Question;
class HomeRepository implements HomeRepositoryInterface
{
public function newest()
{
return $ques = Question::orderBy('created_at', 'DESC')->paginate(10);
}
}
但现在我得到了这样的错误:
Target [App\Repositories\HomeRepositoryInterface] is not instantiable while building [App\Http\Controllers\HomeController].个
那么,这里出了什么问题呢?
我怎么才能解决这个问题呢?