模特不在laravel工作

时间:2014-07-16 18:34:01

标签: laravel laravel-4

控制器名称: UserController.php

public function getIndex()
{
     $users = DB::table('users')->get(); //Working
     $users = User::all(); //Not Working
}

型号名称: User.php

class User extends Eloquent {}

ORM雄辩有什么问题? 我正在使用Laravel 4.2.6

1 个答案:

答案 0 :(得分:0)

fresh laravel 4.2用户模型看起来像这样

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

use UserTrait, RemindableTrait;

/**
 * The database table used by the model.
 *
 * @var string
 */
protected $table = 'users';

/**
 * The attributes excluded from the model's JSON form.
 *
 * @var array
 */
protected $hidden = array('password', 'remember_token');

}

我认为应该这样才能让它发挥作用。