【问题标题】:Method SendMoneyController::index does not exist方法 SendMoneyController::index 不存在
【发布时间】:2021-07-02 12:10:22
【问题描述】:

我正在使用 Laravel 8,我的应用程序在本地运行良好。现在我将应用程序上传到专用服务器,我收到以下错误:

BadMethodCallException 方法 App\Http\Controllers\User\SendMoneyController::index 不存在。

但是,此方法存在,并且在本地服务器上运行良好。

控制器

class SendMoneyController extends Controller
{
    use AmlRulesVerification;

    protected $sendMoneyInterface, $transactionInterface, $recipientInterface, $cardInterface, $homeInterface;

    public function __construct(
        SendMoneyInterface $sendMoneyInterface,
        TransactionInterface $transactionInterface,
        RecipientInterface $recipientInterface,
        CardInterface $cardInterface,
        HomeInterface $homeInterface
    ) {
        $this->sendMoneyInterface = $sendMoneyInterface;
        $this->transactionInterface = $transactionInterface;
        $this->recipientInterface = $recipientInterface;
        $this->cardInterface = $cardInterface;
        $this->homeInterface = $homeInterface;
    }

    public function index(Request $request, $id = null)
    {
        $transaction = $this->sendMoneyInterface->getTransaction($request, $id);
        if (isset($transaction['transaction']->card) && $transaction['transaction']->card) {
            return redirect()->route('send.money.confirmation', ['id' => $id]);
        }
        return view('customers.send_money.index',
            [
                'data' => $transaction,
                'countries' => $this->homeInterface->landingViewData($request)
            ]);
    }
}

web.php

Route::group(['middleware'=>'languageSwitcher'],function () {
    Auth::routes(['verify' => true]);
    Route::get('/', [HomeController::class, 'landingView'])->name('landing.view');
    Route::get('users/registration', [UserController::class, 'showRegisterForm'])->name('user.registration');
    Route::get('localization/change/language', [LanguageSwitcher::class, 'changeLanguage'])->name('LangChange');
    Route::post('/set/email/session', [UserController::class, 'setEmailInSession']);

    Route::group(['middleware'=>'auth'],function () {
        Route::get('/home', [HomeController::class, 'index'])->name('home');
        Route::get('/send/money', [UserSendMoneyController::class, 'index'])->name('send.money.index');
    )};
)};

【问题讨论】:

  • 它在哪个文件/行上抛出错误?
  • 你更新作曲家了吗?
  • 当我更新时我显示不要以 root/超级用户身份运行 Composer!有关详细信息,请参阅getcomposer.org/root 使用包信息加载作曲家存储库来自repo.packagist.org 的警告:不推荐使用对 Composer 1 的支持,并且某些包将不可用。您应该升级到 Composer 2。请参阅 blog.packagist.com/deprecating-composer-1-support 更新依赖项(包括 require-dev)已杀死

标签: laravel laravel-controller


【解决方案1】:

请验证 UserSendMoneyController 中的命名空间

Route::get('/send/money', [User\UserSendMoneyController::class, 'index'])->name('send.money.index');

如果在“app\provider\RouteServiceProvider”中注释了这一行,请尝试这些更改,然后取消注释

 protected $namespace = 'App\\Http\\Controllers';

【讨论】:

  • 你能运行这个命令吗 php artisan route:clear
【解决方案2】:

你为什么要使用一个你已经设置为 null 的变量?

 public function index(Request $request)
    {
        $transaction = $this->sendMoneyInterface->getTransaction($request);
        if (isset($transaction['transaction']->card) && $transaction['transaction']->card) {
            return redirect()->route('send.money.confirmation');
        }
        return view('customers.send_money.index',
            [
                'data' => $transaction,
                'countries' => $this->homeInterface->landingViewData($request)
            ]);
    }

【讨论】:

    猜你喜欢
    • 2019-04-11
    • 2021-04-04
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 2018-07-26
    相关资源
    最近更新 更多