Reputation: 2895
I'm trying to pass some data to a view and it appears as though the view is not getting it. Here is the getProfile route in my controller:
public function getProfile($username)
{
if(User::userExists($username))
{
if($username == Auth::user()->username)
return View::make('user.profile');
else
return View::make('user.profile')->with('user-requested', $username);
}
The view is supposed to change based on whether the parameter $username is the user logged in, in which it will display more information and allow editing and if not then limited information will be displayed. I am checking the session 'user-requested' key in my view as follows:
Username: {{ Session::get('user-requested'); }}
and also like the following:
@if(!Session::has('user-requested'))
//display full profile info
@else
//display limited profile info
Currently the view just displays the full profile info block regardless of whether I enter a username parameter that is not the currently logged in user. The session variable 'user-requested' seems to be null but I am unsure why, is there any reason for this?
Upvotes: 0
Views: 830
Reputation: 1234
You don't need to use Session to get user-requested variable in view, just use it simple something like this.
@if(isset($user-requested))
@else
@endif
To put data in session you have to use Session::put('key','value')
. The only way the variables are set in Sessions using with()
is when they are used with redirects.
Upvotes: 2