php - Laravel call method once model loaded -


i trying check in constructor of model if authenticated user allowed access given model, finding $this constructor's context empty. attributes assigned model in laravel , how should go calling method once of attributes have been loaded?

public function __construct(array $attributes = []) {     parent::__construct($attributes);     var_dump($this); // empty model     $this->checkaccessible();  } 

cheers in advance

you can use controller filter check whether user logged in or not , call model function.

public function __construct(array $attributes = []){        $this->beforefilter('auth', array('except' => 'login')); //login route     if(auth::user()){         $user_id = auth::user()->user_id;         $model = new model($attributes);         //$model = user::find($user_id);    }  } 

binding attributes model constructor

model.php

public function __construct(array $attributes = array()) {     $this->setrawattributes($attributes, true);     parent::__construct($attributes); } 

Comments