How can i put page loader in laravel controller's function?

只愿长相守 提交于 2021-01-28 05:14:56

问题


I am routing my user's to third party URL.

Now whenever they are routing there is a blank page or default tab which is open is displaying, but they are actually redirecting on that URL.

What i want to do like as soon as that routing first function called i need to put page loader there so user's come to know that they are redirecting.

How can i do that in controller ? I can load view file i know but after that remaining code will not work of that function.

Guide me over here.

Thanks in advance.

I tried loading view file but it was not run remaining code.


回答1:


Simply direct your users to a holding page, and then run some simple javascript redirects to get them to their actual destination.

app/routes/web.php

Route::get('redirect', 'YourController@redirect');

app/Http/Controllers/YourController.php

public function redirect(Request $request) {
    $url = $request['url'];
    return view('holding-page', compact('url'));
}

resources/views/holding-page.blade.php

<script type="text/javascript">
    // Redirect the user to where they want to go after 3 seconds.
    setTimeout(function() {
        window.location.replace("{{ $url }}");
    }, 3000);
</script>

Make sure you url encode any urls that you pass as a query string parameter. https://yoursite.com/redirect?url=https%3A%2F%2Fstackoverflow.com



来源:https://stackoverflow.com/questions/55690369/how-can-i-put-page-loader-in-laravel-controllers-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!