2

I'm just beginning to learn how to use Laravel and I'm running into a problem with returning multiple variables.

In my controller I have it set up as:

return view('pages.about')->withFullName($fullname)->withEmail($email);

Then in my view I have:

<p>Email me at {{$email}}</p>

The $fullname variable passes without any problem but when I have the additional variable $email in there it's giving me a parse error.

4
  • have you checked by {{dd(email)}} OR {{dump($email)}} Commented May 1, 2018 at 3:19
  • You are using Laravel 'magic methods', I have tested your code and there is no reason it should not work. It is likely that you have an extra parentheses or something in your view causing the error. Commented May 1, 2018 at 3:48
  • Share more code? Commented May 1, 2018 at 5:26
  • @user2963379, please mark the correct answer (by clicking the checkbox). Commented May 2, 2018 at 17:52

3 Answers 3

1

There are several different ways to pass variable to views. You can try it using below mentioned ways -

  1. $data['fullname'] = $fullname; $data['email'] = $email; Then return view('pages.about', $data);

  2. Another way can be using compact like this return view('pages.about', compact('fullname', 'email'))

  3. If you want to use your current approach, then change it to return view('pages.about')->with(compact('fullname'))->with(compact('email'));

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

Comments

0

You are using a fancier, newer syntax, and it's possible that there's a bug.

Try this:

return view('pages.about')->with('fullName', $fullname)->with('email', $email);

Comments

0

Without seeing all of your code... if the error is showing this line where you return the view it's likely that the line before it hasn't got a semicolon at the end. The chained dynamic with* shouldn't be causing any issues.

Comments

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.