Location headers in Laravel

北慕城南 提交于 2019-12-03 16:34:12

I'm not sure I follow. Laravel sets the Location header as part of the Redirect::to() method. If you want to more explicitly define the response you could do it like this.

return Response::make( '', 302 )->header( 'Location', $url );

If that doesn't work I'd probably just fall back on the php stdlib header() and return null.

If all of this still doesn't do any good, maybe the profiler is messing things up. If it is turned on, try disabling it in the config.

return redirect()->to('url')->send();

Sends HTTP headers and content. In my application, send() method acts like 'exit()' and is testable

exit; after header to stop further code execution.

<?php
header('Location: http://www.example.com/');
exit;

try

return Redirect::to('url');

For example, For this route:

Route::get('hello', array('as' => 'hello_name', 'uses' => 'HelloController@getHello'));

In laravel, you can redirect to url simply using

return Redirect::to('hello');

Alternatively, you can redirect to named route simply using

return Redirect::route('hello_name'); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!