codeforfood
codeforfood

Reputation: 439

Laravel throwing parse error whenever model is referenced in Controller

I have a pretty major problem with my code. Whenever I reference my model in my controller, Laravel throws a parse error. I have gone through my code many times, and do not see any grammatical problems or anything. Anyway, here is my code:

<?php
class CaseController extends BaseController{

public function index()
{

$cases = Case::all();

return View::make('index', compact('cases'));
}

public function create(){

    return View::make('create');
}

public function handleCreate(){

    $case = new Case;
    $case->name=        Input::get('name');
    $case->value=       Input::get('value');
    $case->contentions= Input::get('contentions');
    $case->notes=       Input::get('notes');
    $case->side=        Input::get('side');

    $case->save();

}

}

Here is my Eloquent model:

<?php

class Case extends Eloquent{


}

The parse error is thrown on this line:

$cases = Case:all();

However, when I erase the line

$cases = Case:all();

The parse error is thrown on this line:

$case = new Case;

It seems that whenever i mention the model Case in my code, laravel throws a parse error.

Any help would be greatly appreciated. Thank you!

Upvotes: 1

Views: 476

Answers (1)

Sam
Sam

Reputation: 20486

CASE is a reserved word used in switch statements, example:

switch($a) {
    case 'foo':
        $b = true;
        break;
    case 'bar':
        $b = false;
        break;
    default:
        die('Not found!');
}

You are going to need to rename your class to something different. Also when initializing a class, the proper syntax is:

$case = new Case();
// instead of:
// $case = new Case;

Upvotes: 3

Related Questions