L
L
Ler Den2016-08-11 01:09:04
Laravel
Ler Den, 2016-08-11 01:09:04

How to make a delayed redirect in Laravel?

A trivial task, but I can not solve it for two hours already. There is a simple page with a link.
Task: when you click on the link, a certain page opens, let's call it 'test' , from which a redirect occurs to the required page, let's call it 'final'. On the 'test' page, we display a simple string "You are being redirected..." and with a delay of 2-3 seconds we redirect to 'final'.
As I see :
routes.php

Route::get( '/test'  ,'Production\[email protected]');

website.php
public function TestPage()
    {
      view('production.pages.home.test');  
      sleep(3); 
      Redirect::to('https://final.com', 301); 
    }

As a result, I get an empty window. Of course, you need to add return, but then one thing will be done - either displaying the page or redirecting.
Help me please.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Aksentiev, 2016-08-11
@Sanasol

Either you do a 301 redirect, or you show a page that has a meta/js redirect and it won't be a 301 redirect anymore.
There is no third.

view('production.pages.home.test');  
sleep(3); 
Redirect::to('https://final.com', 301);

26326068d049fcc7301199f97240.png

R
Roman, 2016-08-11
@r_zaycev

Redirect already in the browser using JS or meta http-equiv="refresh". There already and set the delay.

S
Stanislav Pochepko, 2016-08-11
@DJZT

This is done using js on the page itself. and using sleep() stops the execution of the php script for a while and in the end you won't even get the page, because you did a redirect at the header http headers level with php.

D
Dmitry Evgrafovich, 2016-08-11
@Tantacula

nimishprabhu.com/header-php-refresh-redirect-locat...
https://laravel.com/docs/5.1/responses#attaching-h
... .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question