【问题标题】:laravel 8 repository class not found未找到 laravel 8 存储库类
【发布时间】: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 根文件夹

标签: php laravel laravel-8


【解决方案1】:

由于您使用use App\Repositories\BankRequests\BankRequestRepository;,因此您的repositories/ 文件夹应放在app/ 文件夹内,而不是根文件夹内。还要确保您在存储库文件中使用namespace App\Repositories\BankRequests

在移动您的文件夹(并可能编辑您的命名空间)后,运行 composer dumpautoload 让作曲家获取这些更改。

【讨论】:

    猜你喜欢
    • 2016-08-27
    • 2018-11-25
    • 2018-01-02
    • 2021-03-13
    • 1970-01-01
    • 2021-02-12
    • 2021-09-28
    • 2022-01-01
    • 2021-01-08
    相关资源
    最近更新 更多