1

I'm having trouble accessing a variable passed to a view in laravel blade.

I've had no problems before - in this case though I'm setting the variable and using a redirect as follows:

return Redirect::route('members.create')
                ->withInput()
                ->with('test1', 'Email address already exists.');

Then in my view i'm trying to echo out the result as follows:

{{ (isset($test1) ? $test1 : "No Error" )}}

I know the error message exists as I can see it set in the profiler but any attempts to access $test1 gets an error: undefined variable

I'm doing something very basic but obviously making a basic erro

Can someone help and tell me what is my schoolboy error!

Thank you

2 Answers 2

2

is that the exact code? As it doesn't add up - you can't get undefined variable if you are checking isset($test1).

Do a search for $test1 in your view to see if you are trying to call it anywhere else without an isset check.

Also double check you haven't done something silly like written $test instead of $test1

Sign up to request clarification or add additional context in comments.

1 Comment

Hi - not 100% I copied over the relevant code. You are correct the error occurs with trying to echo without the check if the value is set. But the problem relates the the variable not being available when it should. or so I thought...
1

Check for your variable using the static get method in Session.

1 Comment

YES! YOUr right the variable was in a session as flash data. I hadnt understood that a redirect with uses a session as opposed to View::make()->with() is passed as a variable. I was able to access the variable using: Session::get('test1') Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.