我第一次尝试发送使用模型并遇到混乱。当我运行查询时,规则与之链接,应该是这样吗?
模型:
class User extends Elegant
{
public static $table = 'users';
protected $rules = array(
'email' => 'required|email',
'firstname' => 'required',
'lastname' => 'required',
'initials' => 'required|alpha|match:/[A-Z]+/',
'role' => 'required|in:writer_fr,writer_en,reader',
'password' => 'min:6,max:32|same:password2'
);
public static function has_role($role)
{
//$u = new User;
$users = User::where($role, '=', 1)->get(array('firstname', 'lastname'));
return $users;
}
}
控制器
$u = array();
$u['writer_en'] = User::has_role('writer_en');
dd($u['writer_en']);
它打印出整个模型规则、消息、关系等逻辑。我做错了什么还是这正常?