Laravel控制器的依赖注入问题?

时间:2019-01-20 07:22:03

标签: laravel dependency-injection

我设置了依赖注入,因为我觉得它应该进入我的患者控制器,但是由于某种原因,它将永远不会对最后一行的index函数执行依赖,它甚至会返回$ request数据,但是对于某些原因将不会执行我尝试返回的患者资料库中的数据。

我试图做: return (new Patient)->getByAccNumAndDateOrZip($this->client_code, $this->account_number, $this->dob, $this->zip);

另外请记住,是的,所有$ requests都具有有效值,并且不返回空值或空值。

仍然没有任何回报。...

namespace App\Http\Controllers\api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

//Repositories
use App\Repositories\Patient;

class PatientController extends Controller {
  private $patient;

  public function __construct(Patient $patient) {
    $this->middleware('auth.client');
    $this->patient = $patient;
  }

  public function index(Request $request) {
    //I can do return $request->client_code
    //But I can't use this dependency... It's weird...
    return $this->patient->getByAccNumAndDateOrZip($request->client_code, $request->account_number, $request->dob, $request->zip);
  }
}

我希望致电我的依从关系,该依依关系可以将我的所有患者通过帐号提取。依赖关系只是一个带有App \ Repositories命名空间的标准类,它没有设置构造函数,只有几个标准公共函数将在函数中使用特定变量。

1 个答案:

答案 0 :(得分:0)

查看laravel中的日志文件后,我能够看到系统指出类名已被使用,因此我必须选择其他名称。

马特·沃勒(Matt Wohler)建议检查日志,男孩帮助了我!

再次感谢您的帮助!