0

I get this Error Message with this Code:

Error Message:

Undefined variable: user

Code:

@if($user->VIP == true)<span class="label label-VIP">VIP</span>@endif</span>

I think i must include to my blade the ProfileController or how can i do it?

This code works in the User Profile.

Thanks

1
  • update the your blade,controller, route code please Commented Dec 15, 2017 at 10:32

3 Answers 3

1

when you call a view you need to specificate your parameter

in you controlloer class

public function MyFunction(Request $request){
   $myData = "Hello!"
   view('myview',['Text' => $myData ]);
}

or in you routefile

Route::get('/HelloPage', function () {
    $myData = "Hello!"
    view('myview',['Text' => $myData ]);
}

or with utl paramiter

Route::get('/HelloPage/{Text}', function ($Text) {
    view('myview',['Text' => $Text]);
}

on your .blade.php file you have to write

echo $Text;
Sign up to request clarification or add additional context in comments.

3 Comments

in your controller
if you give me a second rewrite the answer specifying better
Thanks, i am beginner
0

not very much clear but you can do something like this in you controller

public function your_function(){
$user = [
"VIP" => true,
]
 return view(your_blade_view)->with('user',$user);
}

just enter your view name without ".blade.php" extension

Comments

0

You can pass a specific parameter with your view file or blade file from a controller.

for example.

public function index(){
  $name = 'foo bar';
  return view('index')->withName($name);
} 

Print in blade file

{{ $name }}

OR

public function index(){
  $data = 'Hello world';
  return \View::make('index')->with('data',  $data);
} 

Print in blade file

{{ $data }}

OR

public function index(){
  return view('index')->with('data', 'hello world');
} 

Print in blade file

{{ $data }}

OR

public function index(){
  return view('index')
        ->with('first_name', 'foo')
        ->with('last_name', 'bar');

} 

Print in blade file

{{ $first_name }}
{{ $last_name }}

OR

public function index(){
    $first_name = 'foo';
    $last_name = 'bar';
    return view('index', compact('first_name', 'last_name'));
}

Print in blade file

{{ $first_name }} 
{{ $last_name }}

OR

public function index(){
  return view('index', [
    'data' => ['hello', 'world', 'welcome']
 ]);
} 

Print in blade file

print_r($data);

OR

public function index(){
  $data = [
        'first_name' => 'foo',
        'last_name' => 'bar'
    ];
    return view('index', compact('data'));
} 

Print in blade file

print_r($data); 
{{ $data['first_name'] }}

Comments

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.