Laravel, using packages with PSR-4 gives message “No hint path defined for”

亡梦爱人 提交于 2019-12-05 12:54:11

The problem is in the usage of the PSR-4 Since Laravel default is PSR-0 it assumes that the resources (views etc) of a package will be 2 levels up from where the package service provider is. Ex:

src
├── config
├── lang
├── migrations
├── Ghunti
│   └── Subby
│       └── SubbyServiceProvider.php
├── routes.php
└── views
    └── user
        └── login.blade.php

With PSR-4 the package service provider and the views will be at the same level (and the error "No hint path defined for" will show up:

src
├── config
├── lang
├── migrations
├── SubbyServiceProvider.php
├── routes.php
└── views
    └── user
        └── login.blade.php

To fix this, on the package service provider boot() method, instead of:

public function boot()
{
    $this->package('ghunti/subby');
}

we need to specify the resources path (the 3rd parameter)

public function boot()
{
    //For PSR-4 compatibility we need to specify the correct path (3rd parameter)
    $this->package('ghunti/subby', null, __DIR__);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!