Laravel 5.1-5.8中的先前路线名称 [英] Previous route name in Laravel 5.1-5.8

查看:56
本文介绍了Laravel 5.1-5.8中的先前路线名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在Laravel 5.1中找到先前路线的名称. 使用:

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 get for current page:

{!! Route::current()->getName() !!}

我的客户不会为谢谢页面输入其他文字,具体取决于用户页面(注册页面联系页面),用户转到谢谢您的页面.我尝试:

My client wont a different text for Thank you page, depends on from page (Register page or Contact page) user go to Thank you page. I try with:

{!! Route::previous()->getName() !!}

但这没用.我尝试得到类似的东西:

But that didn't work. I try to get something like:

@if(previous-route == 'contact')
  some text
@else
  other text
@endif

推荐答案

这对我有用.我找到了这个答案和这个问题,并对其进行了修改以适合我的情况: https://stackoverflow.com/a/36476224/2807381

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

Robert

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

这篇关于Laravel 5.1-5.8中的先前路线名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆