Laravel4 Model :: all()不起作用

时间:2013-12-18 23:06:23

标签: laravel-4 eloquent

有人可以帮助,为什么第一个$ eq会导致500错误? 提前谢谢。

routes.php文件

Route::get('page', function()
{

        $eq = Equip_for_sale::all();                // Not Working !
        $eq = DB::table('equip_for_sale')->get();   // Working !
        return View::make('page')->with('eq', $eq);
});

模型/ Equip_for_sale.php

   class Equip_for_sale extends Eloquent {

    protected $table = 'equip_for_sale';

    }

视图/ page.php文件

var_dump($eq);

1 个答案:

答案 0 :(得分:2)

Laravel希望StudlyCaps班级名称Laravel符合PSR编码标准。

根据PSR编码风格:

Class names MUST be declared in StudlyCaps and Method names MUST be declared in camelCase.

https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md

所以,

class EquipForSale extends Eloquent {

    protected $table = 'equip_for_sale';

    }

并在您的控制器中:

$eq = EquipForSale::all();