Reputation: 165
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.
Upvotes: 2
Views: 4439
Reputation: 12450
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.
Upvotes: 0
Reputation: 3397
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);
Upvotes: 0
Reputation: 1231
There are several different ways to pass variable to views. You can try it using below mentioned ways -
$data['fullname'] = $fullname; $data['email'] = $email;
Then return view('pages.about', $data);
Another way can be using compact like this return view('pages.about', compact('fullname', 'email'))
If you want to use your current approach, then change it to return view('pages.about')->with(compact('fullname'))->with(compact('email'));
Upvotes: 1