流明 - 类网址不存在

时间:2016-01-21 07:22:35

标签: php laravel lumen lumen-5.2

我正在使用Lumen创建一个网站,而我的控制器,路由和视图配置得很好,当我尝试在控制器中使用重定向功能时出现错误。

这是错误代码:

ReflectionException in Container.php line 736: Class url does not exist

in Container.php line 736
at ReflectionClass->__construct('url') in Container.php line 736
at Container->build('url', array()) in Container.php line 631
at Container->make('url', array()) in Application.php line 203
at Application->make('url') in Redirector.php line 39
at Redirector->to('http://opentracker.local/token/archived', '302', array(), null) in helpers.php line 246
at redirect('http://opentracker.local/token/archived') in TokenController.php line 51
at TokenController->unarchive('clickid')
at call_user_func_array(array(object(TokenController), 'unarchive'), array('clickid')) in Container.php line 507
at Container->call(array(object(TokenController), 'unarchive'), array('attribute' => 'clickid')) in RoutesRequests.php line 567
at Application->callControllerCallable(array(object(TokenController), 'unarchive'), array('attribute' => 'clickid')) in RoutesRequests.php line 534
at Application->callLumenController(object(TokenController), 'unarchive', array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 507
at Application->callControllerAction(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 475
at Application->callActionOnArrayBasedRoute(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 460
at Application->handleFoundRoute(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 434
at Application->handleDispatcherResponse(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController@unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 367
at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 610
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 368
at Application->dispatch(null) in RoutesRequests.php line 313
at Application->run() in index.php line 28

我的路线得到了很好的认可,(你可以看到它在错误中应该变换了。)

以下是我在控制器中使用的代码:

public function unarchive($attribute){
    Token::query()->find($attribute)->update(['is_archived'=>0]);
    return redirect(route('token.archived'));
}

我还从boostrap / app.php取消注释了以下内容:

$app->withFacades();
$app->withEloquent();

使用带有流明的函数redirect()是否存在问题?我尝试了redirect(route())redirect()->route(),他们给出了相同的结果。

1 个答案:

答案 0 :(得分:2)

如果你在5.2,那么就会有一个问题。

Lumen - Github Issues - redirect() doesn't work, Lumen 5.2 #315

如果需要,您可以直接使用Illuminate\Http\RedirectResponse。 (来自下面的解决方法链接):

return new RedirectResponse('login');
return RedirectResponse::create('login');

Possible workaround from Github Issue