我在变量中有控制器@方法名,我想得到这个控制器的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;
}
}