Add an anchor to Laravel redirect back

后端 未结 2 542
無奈伤痛
無奈伤痛 2021-02-18 21:49

In a Laravel controller I have this redirect:

    return redirect()->back();

Which returns me to my previous page (say http://domain/page).

相关标签:
2条回答
  • 2021-02-18 22:31
    return Redirect::to(URL::previous() . "#whatever");
    

    And remember to import it at the top:

    use Illuminate\Support\Facades\Redirect;
    use Illuminate\Support\Facades\URL;
    

    I hope this works for you!

    0 讨论(0)
  • 2021-02-18 22:40

    You can use these helpers for laravel 5.5 and above - no imports :-)

    return redirect()->to(url()->previous() . '#hash');
    
    0 讨论(0)
提交回复
热议问题