【问题标题】:Action not defined - ErrorException in UrlGenerator.php line 605未定义操作 - UrlGenerator.php 行 605 中的 ErrorException
【发布时间】:2017-06-15 07:59:54
【问题描述】:

我收到以下错误:UrlGenerator.php 第 605 行中的 ErrorException: Action App\Http\Controllers\VehicleController@processLead not defined。

我已经使用command php artisan route:list 检查了路由是否存在,确实存在。

路由\web.php

<?php

use App\Http\Controllers\BaseController;
use App\Http\Controllers\VehicleController;
use App\Http\Requests\ValidateLeadValues;
use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/

Route::get('/', 'IndexController@index');
Route::get('usedcars/', 'VehicleController@index');
Route::post('processLead/{id}', function ($id, ValidateLeadValues $leadValues, VehicleController $vehicleController)
{
    return $vehicleController->processLead($id, $leadValues);
})->where(['id' => '[0-9]+']);

我的视图文件中有以下内容。该代码在我的表单操作中,当我删除它时,页面加载正常。

{{ action('VehicleController@processLead', ['id' => $vehicle->id]) }}

【问题讨论】:

  • 你更新什么了吗?也许你在不同的库上有错误的版本。
  • 是的,我更新了作曲家。更新前一切正常,现在我收到此错误。

标签: php routes laravel-5.3


【解决方案1】:

App\Http\Controllers\VehicleController 中有公共方法 processLead 吗?

尝试将视图更改为 {{ url('processLead', [$vehicle->id]) }}

我认为问题出现了,因为路由没有直接用控制器方法注册。

【讨论】:

  • 我知道你还没有足够的积分,但只要你得到它们,你应该把它作为评论,而不是答案
  • 是的,我有公共方法 processLead()。将 action() 更改为 url() 不起作用,因为我猜 laravel 不知道该 url 使用哪个控制器?
  • 如何直接用控制器方法注册路由?我在路由文件中注册它的方式还没有这样做吗?
  • 如果在运行 composer update 之前已经成功,请尝试清除 laravel 的缓存: php artisan route:clear;php artisan cache:clear;php artisan config:clear
  • 我尝试了这些命令,但仍然收到错误消息。这真的很令人困惑,因为自从它工作以来我唯一做的就是运行作曲家更新。
猜你喜欢
  • 2017-09-07
  • 2017-08-13
  • 2017-10-09
  • 2017-05-14
  • 1970-01-01
  • 2018-12-12
  • 2021-08-22
  • 2023-03-05
  • 2018-01-26
相关资源
最近更新 更多