user2963379
user2963379

Reputation: 165

php laravel Parse error: syntax error, unexpected 'return' (T_RETURN)

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

Answers (3)

Dwight
Dwight

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

parker_codes
parker_codes

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

Jobayer
Jobayer

Reputation: 1231

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'));

Upvotes: 1

Related Questions