Reputation: 291
I am using Lumen to create a website, and while my controllers, routes, and views are well configured, I get an error when I try to use the redirect function in a controller.
This is the error code :
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
My route is well recognized, (you can see it transformed as it should in the error).
Here is the code that I use in my controller :
public function unarchive($attribute){
Token::query()->find($attribute)->update(['is_archived'=>0]);
return redirect(route('token.archived'));
}
I also uncommented the following from boostrap/app.php :
$app->withFacades();
$app->withEloquent();
Is there a problem using the function redirect()
with Lumen ? I tried both redirect(route())
and redirect()->route()
, and they gave the same result.
Upvotes: 0
Views: 1624
Reputation: 50491
If you are on 5.2 there is an issue open for this.
Lumen - Github Issues - redirect() doesn't work, Lumen 5.2 #315
You can use the Illuminate\Http\RedirectResponse
directly if needed. (from workaround link below):
return new RedirectResponse('login');
return RedirectResponse::create('login');
Possible workaround from Github Issue
Upvotes: 2