将操作重定向到不同命名空间中的控制器
Redirect action to controller in different namespace
我有使用重定向调用控制器然后显示视图的中间件。
public function handle($request, Closure $next)
{
redirect()->action('Full\Namespace\To\Controller\ErrorController@fourOhThree');
}
我也有这个路线。当我沿着路线行驶时,视图显示良好。当我尝试使用 action
重定向并传递我的控制器的名称空间时,laravel 尝试在基本应用程序中找到控制器。我收到错误
Action App\Http\Controllers\Full\Namespace\To\Controller\ErrorController@fourOhThree not defined.
当控制器位于
App\Vendor\Myname\Mypackagename\Controllers\ErrorController@fourOhThree
据我所知,我已正确命名我的控制器,因为它与此目录中的其他命名空间控制器相匹配。这是我尝试从操作中调用的唯一控制器。
ErrorController.php
App\Vendor\Myname\Mypackagename\Controllers
以内
namespace Full\Namespace\To\Controller;
use App\Http\Controllers\Controller;
class ErrorController extends Controller
{
public function fourOhThree()
{
return view('...');
}
}
我认为我在将命名空间控制器传递给 action
方法时做错了什么。
尝试在限定名称前添加一个“\”。
action('\Full\Namespace\To\Controller\ErrorController@fourOhThree')
我有使用重定向调用控制器然后显示视图的中间件。
public function handle($request, Closure $next)
{
redirect()->action('Full\Namespace\To\Controller\ErrorController@fourOhThree');
}
我也有这个路线。当我沿着路线行驶时,视图显示良好。当我尝试使用 action
重定向并传递我的控制器的名称空间时,laravel 尝试在基本应用程序中找到控制器。我收到错误
Action App\Http\Controllers\Full\Namespace\To\Controller\ErrorController@fourOhThree not defined.
当控制器位于
App\Vendor\Myname\Mypackagename\Controllers\ErrorController@fourOhThree
据我所知,我已正确命名我的控制器,因为它与此目录中的其他命名空间控制器相匹配。这是我尝试从操作中调用的唯一控制器。
ErrorController.php
App\Vendor\Myname\Mypackagename\Controllers
namespace Full\Namespace\To\Controller;
use App\Http\Controllers\Controller;
class ErrorController extends Controller
{
public function fourOhThree()
{
return view('...');
}
}
我认为我在将命名空间控制器传递给 action
方法时做错了什么。
尝试在限定名称前添加一个“\”。
action('\Full\Namespace\To\Controller\ErrorController@fourOhThree')