1

I have a very simple setup in Laravel while I'm learning it and I can't figure why I'm getting an error. It's probably something simple I am overlooking.

I can get this:

Route::get('users', function() {
    $users = User::all();
    return View::make('users')->with('users', $users);
});

example on Laravel to work perfectly, displaying this information in a users.blade.php view.

In my database I also have a 'lists' table but when I copy the structure of the code above to try and display my lists I receive the following error.

syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting '('

on line

 $lists = list::all();

My code is as follows routes.php

Route::get('lists', function() {
    $lists = list::all();
    return View::make('lists')->with('lists', $lists);
});

list.php /models

<?php
class List extends Eloquent {}

lists.blade.php /views

@extends('layouts.main')
@section('content')
@foreach($lists as $list)
    <p>{{ $list->name }}</p>
@endforeach
@stop

Any help would be much appreciated. Thanks.

2
  • First glance, it looks like List must be capitalized, since that's the name of your object. That is, try $lists = List::all(); Commented Apr 22, 2014 at 17:01
  • @ChrisForrence Capitalising List::all(); still produces the error. Thanks however Commented Apr 22, 2014 at 17:05

1 Answer 1

2

List is a reserved keyword in PHP, so you may not use it as a class name. From the documentation:

These words have special meaning in PHP. Some of them represent things which look like functions, some look like constants, and so on - but they're not, really: they are language constructs. You cannot use any of the following words as constants, class names, function or method names.

Unfortunately, you're going to need to have a different class name, then set your object's table name to 'lists' like such:

class AppList extends Eloquent { protected $table = 'lists'; }
Sign up to request clarification or add additional context in comments.

2 Comments

A decent editor usually shows this issue, based on syntax highlighting.
Thanks @ChrisForrence - I'd never have guessed this!

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.