In order to pass variables to a view, you have two options:
return View::make('profile.user')
->with('user', $user)
->with('username', $username)
->with('email',$email)
->with('foo',$foo)
->with('bar',$bar);
2.Using arrays
return View::make('profile.user',array(
'user' => $user,
'username' => $username,
'email' => $email,
'foo' => $foo,
'bar' => $bar
));
Let's say you need to get data about the user using the User model. You can send the data like this:
$user = User::find($id);
return View::make('users.show')
->with('name',$user->name)
->with('email',$user->email);
and echo the data into the view like this
{{ $name }} <br/>
{{ $email }} <br/>
OR
You can send the user object as a parameter to the view
$user = User::find($id);
return View::make('users.show')
->with('user',$user-);
and echo the data into the view like this
{{ $user->name }} <br/>
{{ $user->email }} <br/>
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community