Search code examples
phplaravelexceptioncartalyst-sentry

Redirecting to route with text AND variables?


I'm currently using Laravel 4 and Sentry 2 for developing a pretty simple authentication system with throttling enabled. That said, when an exception is thrown as the user attempts to log in because he has been suspended, he should be redirected back to the login view with a message saying "This user has been suspender for $time minutes."

Problem is: I can't return both a variable and a text message to the view. Maybe I'm missing the correct syntax, I don't know. This has been driving me insane as I need to do it for many other exceptions. It seems to be a newbie issue an the solution should be pretty simple.

This is the part of my code which matters:

catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e)
{
    $throttle = Sentry::findThrottlerByUserLogin(Input::get('username'));
    $time = $throttle->getSuspensionTime();

     return Redirect::route('account-sign-in-get')
                    ->with('message','This user has been suspended for [$time] minutes.');


}

Thanks in advance.


Solution

  • Just replace

    ->with('message','This user has been suspended for [$time] minutes.');

    with

    ->with('message', "This user has been suspended for {$time} minutes.");

    What was actually going on:

    In PHP when you use single quote around a string, it does not parse the variable embedded in that string, but when you use double quote, it parses it.