简体   繁体   English

如何重定向到 Laravel 中的两个不同视图?

[英]How to redirect to two different views in Laravel?

I'm a newbie to the Laravel framework.我是 Laravel 框架的新手。 What I want to do is to redirect the users to a wait page firstly, then, they'll be redirected to their homepage after the wait screen.我想要做的是首先将用户重定向到等待页面,然后,他们将在等待屏幕后重定向到他们的主页。

I wrote some code for this but unfortunately it does not work.我为此编写了一些代码,但不幸的是它不起作用。 I searched about it but couldn't find a solution.我搜索了它,但找不到解决方案。

Here is my code:这是我的代码:

function order(Request $req){
    $data = [['user_id'=>Auth::id(),'order_note'=>$req->order_note, 'sugar'=>$req->order_sugar, 'amount'=> $req->amount, 'place_id'=>$req->order_place, 'beverage_id'=>$req->order_beverage]];
    Orders::insert($data);
    $this->redirectToWait(); // this is another function in the same controller.
    sleep(10);
    return redirect()->route('home');
}

function redirectToWait(){
    return redirect()->route('wait');
}

This code only returns to the home route, it skips the redirectToWait() function.此代码仅返回到本地路由,它跳过了 redirectToWait() 函数。

Thank you for your help :)感谢您的帮助 :)

You can't do this only using PHP & Laravel.你不能只使用 PHP 和 Laravel 来做到这一点。 You have to use JavaScript to load first page then second page.您必须使用 JavaScript 加载第一页然后第二页。

Controller:控制器:

function order(Request $req){
    $data = [['user_id'=>Auth::id(),'order_note'=>$req->order_note, 'sugar'=>$req->order_sugar, 'amount'=> $req->amount, 'place_id'=>$req->order_place, 'beverage_id'=>$req->order_beverage]];
    Orders::insert($data);

    return view('wait-step-view-here');
}

wait-step-view-here.blade.php等待步骤视图here.blade.php

...[SOME_HTML_HERE]
<script>
setTimeout(function(){
  window.location.replace("{{ route('home') }}");
}, 10000);
</script>
...[SOME_HTML_HERE]

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

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