【发布时间】:2021-06-18 06:46:57
【问题描述】:
在我的新 laravel 项目中,我在项目的根文件夹中创建了一个存储库文件夹,在该文件夹中有一个 BankRequests 文件夹,其中包含 BankRequestRepository 文件,如下所示:
<?php
namespace App\Http\Controllers;
use App\Repositories\BankRequests\BankRequestRepository;
use Illuminate\Http\Request;
class PaymentRequestController extends Controller
{
private $bankRequestRepository;
public function __construct( BankRequestRepository $bankRequestRepository)
{
$this->bankRequestRepository = $bankRequestRepository;
}
public function payeeValidation(Request $request)
{
dd(1234);
$verifiedPayees= array();
foreach ($request->payees as $payee ){
$ibanOwners= $this->bankRequestRepository->shebaCheck($payee);
$ibanOwnerKey= array_search($payee,$ibanOwners);
$ibanOwner= $ibanOwners[$ibanOwnerKey];
array_push($verifiedPayees, $ibanOwner);
}
return $verifiedPayees;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
在我的 paymentRequestController 中,我使用这样的存储库:
<?php
namespace App\Http\Controllers;
use App\Repositories\BankRequests\BankRequestRepository;
use Illuminate\Http\Request;
class PaymentRequestController extends Controller
{
private $bankRequestRepository;
public function __construct( BankRequestRepository $bankRequestRepository)
{
$this->bankRequestRepository = $bankRequestRepository;
}
public function payeeValidation(Request $request)
{
dd(1234);
$verifiedPayees= array();
foreach ($request->payees as $payee ){
$ibanOwners= $this->bankRequestRepository->shebaCheck($payee);
$ibanOwnerKey= array_search($payee,$ibanOwners);
$ibanOwner= $ibanOwners[$ibanOwnerKey];
array_push($verifiedPayees, $ibanOwner);
}
return $verifiedPayees;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
当我打电话给
Route::post('payment-request/payee-validation', [PaymentRequestController::class, 'payeeValidation']);
它返回错误:
"message": "目标类 [App\Repositories\BankRequests\BankRequestRepository] 不存在。",
我曾经在较旧的 laravel 版本中这样做,没有问题。这是 laravel 8 的问题吗?
【问题讨论】:
-
BankRequestRepository类中的命名空间是否与App\Repositories\BankRequests\BankRequestRepository匹配? -
"在项目的根文件夹中" 在root文件夹还是app文件夹中?跨度>
-
@brombeer 根文件夹