Support the ongoing development of Laravel.io →
Database Views Architecture
Last updated 1 year ago.
0

In order to pass variables to a view, you have two options:

  1. Using the ** with ** method
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
    ));
Last updated 1 year ago.
0

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/>
Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.