Laravel redirect::route is showing a message between page loads

后端 未结 4 1584
天命终不由人
天命终不由人 2021-01-06 04:57

I\'m currently developing a web app using Laravel, and the app was working perfectly fine until recently. I had no idea what triggered it but here\'s a summary of the issue

相关标签:
4条回答
  • 2021-01-06 05:34

    Although Without seeing more of your setup, it will be tricky to debug, you do have an error within your route....

    Route::get('/', array('as'=>'home', 'use'=>'HomeController@show'));
    

    Should be:

    Route::get('/', array('as'=>'home', 'uses'=>'HomeController@show'));
    

    Note the 'uses' as opposed to 'use'.

    Also, theres nothing wrong with Using View::make, however its possibly not the best logic to use, as the user will have content displayed that doesn't fit with the url. Best practice would be to redirect them as you currently are..... Just make sure the route is there for them to hit once redirected.

    0 讨论(0)
  • 2021-01-06 05:36

    I faced same issue and after spending my whole weekend to find actual cause and fix this issue. I landed on this stackoverflow question and felt its same issue as that of mine.

    I used following core php function to redirect instead of returning a view file from controller.

    header('Location: /');
    

    It printed actual file which had blank line. Removing this line fixed my problem.

    There were thousands of files in my code base. My assumption was that I have tried different scripts to find such blank lines at start of any file and there was no such file as per those scripts results. I assumed there is is no blank line in any of my files. But header('Location: /') proved that my assumption was not correct and I was working on wrong lines.

    0 讨论(0)
  • 2021-01-06 05:38

    I had the same problem, the problem for me was I had a space in the base controller before the <?php tag

    0 讨论(0)
  • 2021-01-06 05:47

    In my app the problem was caused by a cast to string:

    public function myAction(): string {
       return redirect('/');
    }
    

    I had to remove : string to prevent the response from being cast to a string.

    0 讨论(0)
提交回复
热议问题