tomczas
tomczas

Reputation: 179

Laravel - displaying variable

I have a problem. I use external library to laravel 5.2 to display weather for airport and I have problem with displaying it in blade.

My controller:

public function showMetar() {
    $egss = new Metar('EGSS');
    $metar = sprintf('The METAR report for Stansted (EGSS) is: %s', $egss);
    return view('home', compact('metar'));
}

And I try to display it in blade using {{ $metar }} and it display me undefined variable metar... Don't know really how to define it to display it in my home.blade

Upvotes: 1

Views: 87

Answers (2)

Matthias Weiß
Matthias Weiß

Reputation: 508

Try a dd($metar); before before you return the view, that's a nice way to check if a variable actually is what it's supposed to be.

Upvotes: 1

jannej
jannej

Reputation: 906

Have you checked the $metar-valiable is not null or empty. Please note that compact() will not issue a warning if the specified variable name is undefined. Therefore I always use this instead:

view('home', ['metar' => $metar]);

Upvotes: 0

Related Questions