在RouteAction.php第84行:无效的路由操作

时间:2018-04-30 06:45:03

标签: laravel

当我在laravel 5.4中创建一个控制器时,我收到此错误

  

在RouteAction.php第84行:

     

无效的路线操作:   [应用\ HTTP \控制器\管理员\ DashboardController]。

我没有创建Admin / DashboardController。仍然出错

web.php

Route::group(['namespace' => 'Admin', 'middleware' => ['auth:web', 'CheckAdmin'], 'prefix' => 'admin'],function (){
    $this->resource('authorities', 'AuthoritiesController');
    $this->resource('complaints', 'ComplaintsController');
    $this->resource('schools-list', 'SchoolsListController');
    $this->resource('inspection-failed', 'InspectionFailedController');
    $this->resource('inspection-register', 'InspectionRegisterController');
    $this->resource('inspection-results', 'InspectionResultsController');
    $this->resource('inspectors-list', 'InspectionListController');
    $this->resource('investigators', 'InvestigatorsController');
    $this->resource('notification-infringement', 'NotificationInfringementController');
    $this->resource('system-experts', 'SystemExpertsController');
    $this->resource('submit-information', 'SubmitInformationController');
    $this->resource('primary-committee-meeting', 'PrimaryCommitteeMeetingController');
    $this->resource('list-violations-school', 'ListViolationsSchoolController');
    $this->resource('announcing', 'AnnouncingController');
    $this->resource('display-vote', 'DisplayVoteController');
    $this->resource('announcing-supervisory-vote', 'AnnouncingSupervisoryVoteController');
    $this->resource('supervisory-board-vote', 'SupervisoryBoardVoteController');
    $this->resource('defense', 'DefenseController');
    $this->resource('votiing-supervisory-board', 'VotiingSupervisoryBoardController');
    $this->get('dashboard', 'DashboardController');
});

6 个答案:

答案 0 :(得分:12)

因为它无效。当您使用GET路由时,必须指定方法名称(除非您使用::resource):

$this->get('dashboard', 'DashboardController@methodName');

答案 1 :(得分:2)

我也面临类似的问题:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', 'Frontend\FrontendController@index')->name('home');
Route::get('/post', 'Frontend\FrontendController@post')->name('post');
Route::get('/contact', 'Frontend\FrontendController@contact')->name('contact_us');
Route::group(['prefix' => 'admin'], function () {

    Route::get('/create', 'Backend\BackendController@index');

    //User Route

    Route::get('/registration', '');
});

我只是删除了Route::get('/registration', '');,它对我来说是有用的:)

答案 2 :(得分:1)

Laravel的新手或学习用途的人

Route::resource('resource_name','controller_name')

为避免在键入时出现此类错误:

php artisan route:list

在cmd或任何其他命令行中。

答案 3 :(得分:1)

我遇到了同样的问题,但原因不同。所以我在这里记录,以防其他人遇到同样的原因。

特别是如果您使用的是单动作控制器(即:带有 __invoke),如果您没有添加或省略正确的 use,Laravel 将使用“无效的路由操作: [XController]。”

这会失败

<?php
use Illuminate\Support\Facades\Route;

Route::post('/order', XController::class);

这会通过

<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\XController;

Route::post('/order', XController::class);

我认为 Laravel 掩盖了潜在问题有点不幸,但我认为它仅适用于可调用控制器,尽管代表我这是一个愚蠢的错误。

答案 4 :(得分:1)

如果您使用的是laravel 8,则需要在数组中添加控制器和方法名称,否则会引发错误。

Route::get('/projects', User\ProjectController::class, 'index')->name('user.projects');

 Route::get('/projects', [User\ProjectController::class, 'index'])->name('user.projects');

答案 5 :(得分:0)

尝试通过以下方式删除路由缓存文件

php手工艺路线:清除