0

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

How can I access the variable $user-requested in the view? It's is stating it's undefined
{{$user-requested}} which is just like <?php echo $user-requested; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.