Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel View Composer "Use of undefined constant"

been looking all evening and it all seems so easy and simple but just won't work!

Just starting out and trying to get a variable into a view.

Whatever i do, i can't seem to read it.

routes.php:

Route::get('/', function()
{
    return View::make('dashboard');
});

View::composer('dashboard', function($view) {
    $view->with('links', "something");
});

dashboard.blade.php:

@extends('base_view')

@section('content')
    All the stuff!
    {{links}}
@stop

base_view.blade.php

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Laravel PHP Framework</title>
</head>
<body>
    <div>TeamPro</div>
    <div>@yield('content')</div>
</body>
</html>

Please tell me i'm just doing something stupid!

like image 776
Ryk Waters Avatar asked Mar 17 '14 22:03

Ryk Waters


2 Answers

Use $links, not links:

@section('content')
    All the stuff!
    {{ $links }}
@stop

Every variable in PHP should be preceded by a $ sign. If there's no $, PHP treats it as a constant.

like image 166
Joseph Silber Avatar answered Nov 10 '22 13:11

Joseph Silber


It's just a simple syntax issue, everything you send to a view is a php variable so still needs to be referenced with the $

In your view, you are referencing links without the dollar sign.

If you update it to:

{{ $links }}

You'll be A-OK

like image 29
duellsy Avatar answered Nov 10 '22 13:11

duellsy