jody_lognoul
jody_lognoul

Reputation: 817

Laravel 4 detect redirection

May be I'm misunderstanding something, but is it possible to detect into the method (GET) of a controller if the request is a Redirection ? I would like to do something like that :

if(Request::statusCode() == '304') {}

Thank you!

Upvotes: 0

Views: 1615

Answers (2)

Pasindu Jay
Pasindu Jay

Reputation: 4510

I got the same problem. after searching, just end up passing a variable with redirect.(I'm using laravel 5).

public function method1(){
    //detect its redirect or not
    if(Session::get('isRedirected')){
        //this is redirect from method2
    }
    else{
        //this is regular call
    }
}
public function method2(){
    return redirect('method1')->with('isRedirected',1);
}

Upvotes: 0

Anam
Anam

Reputation: 12179

According to Laravel Request Api, Laravel does not have any statusCode() method.

http://laravel.com/api/4.1/Illuminate/Http/Request.html

However, you can use php's http_response_code method to detect the response code.

if(http_response_code() == '304') 
{
   // do something
}

Reference:

http://www.php.net/manual/en/function.http-response-code.php

Upvotes: 1

Related Questions