How to make instant redirection in Laravel

后端 未结 3 988
死守一世寂寞
死守一世寂寞 2021-01-21 18:37

I want to make an instant redirection in my controller in Laravel.

I know I can use

public function show($page) 
{   
   return Redirect::url(\'http://ex         


        
3条回答
  •  误落风尘
    2021-01-21 19:11

    After a while of digging it seems that for this purposes you should use send() method from Symfony\Component\HttpFoundation (Laravel RedirectResponse inherits from this class).

    So you can modify checkPages method this way:

    public function checkPages($page, $totalPages, $url) 
    {
      if ($page < 2 or $page > $totalPages)  {
         Redirect::url($url)->send();
      }    
    }
    

    and it will make instant redirection.

提交回复
热议问题