我为我的应用程序创建了一个Contract接口和一个Eloquent Repository,但是当我尝试使用它时,我收到了500错误。
我觉得它与注册方式有关。要使用具有以下register
方法的服务提供商执行此操作:
/**
* Register service provider bindings
*/
public function registerBindings() {
$this->app->bind(
\App\Repositories\Backend\EventContract::class,
\App\Repositories\Backend\EloquentEventRepository::class
);
}
然后我在我的控制器中按如下方式使用合同:
class EventController扩展了Controller {
/**
* @var EventContract
*/
protected $events;
/**
* EventController constructor.
* @param EventContract $events
*/
public function __construct(EventContract $events)
{
$this->events = $events;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('backend.events.index')
->withEvents($this->events->getEventsPaginated(25, 1));
当我加载500错误的页面时,Laravel日志或Nginx日志中没有条目(我使用带有Vagrant的Homestead)。
有什么想法吗? 提前致谢
编辑:找到一些日志!2016/02/17 09:47:52 [error] 1868#0: *331 FastCGI sent in stderr: "inate\Container\Container->make() /home/vagrant/Code/Yoosit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:674
PHP message: PHP 478. Illuminate\Container\Container->build() /home/vagrant/Code/Yoosit/vendor/laravel/framework/src/Illuminate/Container/Container.php:633
PHP message: PHP 479. Illuminate\Container\Container->getDependencies() /home/vagrant/Code/Yoosit/vendor/laravel/framework/src/Illuminate/Container/Container.php:779
PHP message: PHP 480. Illuminate\Container\Container->resolveClass() /home/vagrant/Code/Yoosit/vendor/laravel/framework/src/Illuminate/Container/Container.php:808
PHP message: PHP 481. Illuminate\Foundation\Application->make() /home/vagrant/Code/Yoosit/vendor/laravel/framework/src/Illuminate/Container/Container.php:853
PHP message: PHP 482. Illuminate\Container\Container->make() /home/vagrant/Code/Yoosit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:674
PHP message: PHP 483. Illuminate\Container\Container->build() /home/vagrant/Code/Yoosit/vendor/laravel/framework/src/Illuminate/Container/Container.php:633
PHP message: PHP 484. Illuminate\Container\Container->Illuminate\Container\{closure}() /home/vagrant/Code/Yoosit/vendor/laravel/framework/src/Illuminate/Container/Container.php:735
PHP message: PHP 485. Illuminate\Foundation\Application->make() /home/vagrant/Code/Yoosit/vendor/laravel/framework/src/Illuminate/Container/Container.php:230
PHP message: PHP 486. Illuminate\Container\Container->make() /home/vagrant/Code/Yoosit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:674
PHP message: PHP 487. Illuminate\Container\Container->build() /home/vagrant/Code/Yoosit/vendor/laravel/framework/src/Illuminate/Container/Container.php:633
PHP message: PHP 488. Illuminate\Container\Container->getDependencies() /home/vagrant/Code/Yoosit/vendor/laravel/framework/src/Illuminate/Container/Container.php:779
PHP message: PHP 489. Illuminate\Container\Container->resolveClass() /home
答案 0 :(得分:0)
可能是愚蠢的指针,但没有伤害检查:
仔细检查各个文件中的命名空间,即EventContract 和EloquentEventRepository类文件。
检查是否已在EventController中导入名称空间if 不使用完整路径
在 注册服务提供商你是否运行了composer dump-autoload -o
尝试使用chrome devtools查看调试时的响应