user3723418
user3723418

Reputation:

Passing data to view not working - Laravel 4

I have this code:

if(Auth::check()) {
        Redirect::to('home');
    }
    $user = Auth::user();
    return View::make('HumanResourcesProcess')->with(array('firstName', $user->firstName));

and it gives me the error:

Undefined variable: firstName

But I am defining it in the array part? Any ideas on how to fix it?

Upvotes: 0

Views: 58

Answers (2)

har2vey
har2vey

Reputation: 676

Another alternative you can use is 'compact', especially useful if you have lot's of variable to pass without having to assign them when passing to view:

return View::make('view.name',compact('variable1','variable2','variable3'));

Upvotes: 0

fmgonzalez
fmgonzalez

Reputation: 823

Try this:

return View::make('HumanResourcesProcess')->with('firstName', $user->firstName);

or this one:

return View::make('HumanResourcesProcess')->with(array('firstName' => $user->firstName) );

I hope it works fine.

Upvotes: 2

Related Questions