php - Laravel 3 - Eloquent query returns rules -


i'm trying send use models first time , running confusion. when run query, rules linked it, supposed that?

model:

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;     } } 

controller

$u = array(); $u['writer_en'] = user::has_role('writer_en'); dd($u['writer_en']); 

which prints out entire model rules, messages, relationship etc logic. doing wrong or normal?

in has_role method returning user model

public static function has_role($role) {     //$u = new user;     $users = user::where($role, '=', 1)->get(array('firstname', 'lastname'));     return $users; // <-- user model } 

so, it's dumping user model , it's doing right thing suppose following code

$u = array(); $u['writer_en'] = user::has_role('writer_en'); dd($u['writer_en']); 

instead of dumping model, can use

$user = user::has_role('writer_en'); echo $user->firstname; echo $user->lastname; 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -