0

I'm trying to echo first_name on the page but I couldn't work it out how.

$providerEmail = Auth::user()->email;
  $providerName = Auth::user()->first_name;
    return View::make('account')->with( 'providerEmail', $providerEmail, 'providerName', $providerName);

the ()->email bit works, it echos the user email but when echoing first_name it gives me $providerName error (Undefined variable: providerName).

nCore
  • 2,027
  • 7
  • 29
  • 57

2 Answers2

1

You could clean this up considerably. Rather than assigning a new view variable for each property of your provider, just send the entire provider model to your view like this.

<?php

$provider = Auth::user();

return View::make('account')->with('provider', $provider);

Then in your views, you can access the email, name, and other properties just as you would in your route or controller.

In View

$provider->email
Sajan Parikh
  • 4,668
  • 3
  • 25
  • 28
0

You need one more ->with():

$providerEmail = Auth::user()->email;

$providerName = Auth::user()->first_name;

return View::make('account')->with('providerEmail', $providerEmail)
                            ->with('providerName', $providerName);
Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
  • Thanks, just few seconds you replied I saw that I was missing that ->with(). But Thank you. – nCore Nov 10 '13 at 14:48