简体   繁体   English

在Laravel 5中使用变量重定向URL

[英]Redirect url with Variable in Laravel 5

How to Redirect Url in following format: 如何以以下格式重定向网址:

My code: 我的代码:

return Redirect::to('home/viewcustomer/$cusid')
    ->with('status','success')
    ->with('message','success');

Example : 范例:

home/viewcustomer/8

You need to take care about your string quotes while using variables within string quotes. 你需要采取对你照顾字符串引号 ,而使用字符串引号内的变量。 Just update your code 只需更新您的代码

Redirect::to('home/viewcustomer/$cusid')

into 进入

Redirect::to("home/viewcustomer/$cusid")
            ^^                        ^^

Well i usually use 好吧,我通常使用

Session and Redirect so you have to define it in your controller 会话和重定向,因此您必须在控制器中定义它

Use Session;
Use Redirect;

Then 然后

public function example(){
 Session::flash('status','Your message');
 return Redirect::to('/yourRoute');
}

If you want to show your message in your view you have to do this... 如果要在视图中显示消息,则必须执行此操作...

@if(Session::has('status'))
        <div class="alert alert-success alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            <p><strong>Success!!</strong> </p>
            <ul>
                <li>{{ Session::get('status') }}</li>
            </ul>
        </div>
    @endif

Hope this helps!! 希望这可以帮助!!

Ps: Sorry for the bad english :) ps:对不起,英语不好:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM