vendredi 26 août 2016

How to preserve query string or session variable when redirecting in routes.php in Laravel?

I've got some addon domains pointing to my server at the directory /public_html/. Let's say the addon domains are red-bananas.com and blue-bananas.com, and when someone loads that domain I want it to point to a specific action in my controller. So I have this code at the bottom of my routes.php file:

Route::get('red', 'BananasController@red');
Route::get('blue', 'BananasController@blue'); 
Route::any('/', function()
{

    switch( Request::getHost() ){
        case 'red-bananas.com':
            return redirect()->action('BananasController@red');
            break;
        case 'blue-bananas.com':
            return redirect()->action('BananasController@blue');
            break;

    }
});

I notice if you were to go to red-bananas.com, you get redirected to the URL red-bananas.com/red, and if you go to blue-bananas.com you get redirected to http://ift.tt/2c2qmQp. This is fine, but I sometimes have tracking query strings I need on my URLs, like this:

red-bananas.com?tid=123

Ideally I'd like to be able to store in the session the value of '123' to 'tid', but if I do Session::put('tid', '123') above

return redirect()->action('BananasController@red');

It doesn't work - nothing gets stored in the session and the tracking data is lost. How can I preserve the tracking data? I need someone to be able to load up the URL red-bananas.com?tid=123 and it triggers the red function in my BananasController where I can access the value of tid.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bvIsaJ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire