2

I know it's probably super simple, but I just started using laravel today, I've always been on codeigniter before. The problem I have is that laravel tells me that my variable is not defined ...

Controller:

public function index()
{

    $data['pageTitle']='Connexion';

    return view('login')->with($data);
}

The line concerned in login.blade.php:

@extends('layout.header', $pageTitle)

Error:

"Undefined variable: pageTitle (View: G:\Winginx\home\laravel\public_html\resources\views\login.blade.php)"

Thanks !

1
  • why are you passing a second argument to the extends directive? btw Commented Dec 25, 2017 at 19:47

1 Answer 1

2

You're getting this error because you're trying to use $pageTitle variable but you do not pass it to the view.

So, to fix this you can change this line in the view:

@extends('layout.header', $data['pageTitle'])

Or you can change method in controller to:

public function index()
{
    return view('login', ['pageTitle' => 'Connexion']);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Not working, the first method now give this error: Undefined variable: data and second do same thing :/
@KarylLamoureux I'm pretty sure you can't get this error message. You're doing something wrong, because the code above is 100% working.

Your Answer

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