Previous route name in Laravel 5.1-5.8

前端 未结 4 1146
迷失自我
迷失自我 2020-12-10 13:22

I try to find name of previous route in Laravel 5.1. With:

{!! URL::previous() !!}

I get the route url, but I try to get route name like I

4条回答
  •  一向
    一向 (楼主)
    2020-12-10 13:37

    Here what work for me. I find this answer and this question and modify it to work in my case: https://stackoverflow.com/a/36476224/2807381

    @if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'public.contact')
        Some text
    @endif
    

    Update for 5.8 version by Robert

    app('router')->getRoutes()->match(app('request')->create(url()->previous()))->getName()
    

提交回复
热议问题