使用操作助手

时间:2016-11-06 19:55:27

标签: php laravel url-routing laravel-5.3

我在变量中有控制器@方法名,我想得到这个控制器的url,所以我在Laravel中使用action() Helper,但是我收到了这个错误:

InvalidArgumentException in UrlGenerator.php line 605:
Action App\Http\Controllers\Dashboard\Users\UserController@index not defined. 

这是我的route/web.php

Route::group(['middleware' => ['auth','nav'], 'prefix' => 'dashboard', 'namespace' => 'dashboard'], function () {
    Route::get('/', 'DashboardController@index')->name('dashboard');

    Route::group(['prefix' => 'users', 'namespace' => 'users'], function () {
        Route::get('/list', 'UserController@index');
    });
});

并在变量I中存储此字符串:

Dashboard\Users\UserController@index

有什么问题?

更新:

我在中间件中使用action() Helper:

<?php

namespace App\Http\Middleware;

use App\Models\User\Nav;
use Closure;
use Illuminate\Support\Facades\View;

class NavMenu
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        ...
        $sample = $this->createNavigation();
        ...
        return $next($request);
    }

    public function createNavigation()
    {
        ...
        $url = action('Dashboard\Users\UserController@index');
        ...

        return $url;
    }
}

0 个答案:

没有答案