jeudi 7 juillet 2016

Eloquent Model access relational data on method call

We have two models and method history:

class Employment_request extends Model {
    protected $table = 'employment_requests';
    // some code here
    public function history(){
        return $this->hasMany('App\Employment_history');
    }
}


class Employment_history extends Model {
     protected $table = 'employment_history';
     // some code
}

Lets create instance of Employment_request:

$r = Employment_request::find(28)

In this case method history data is requested when instance of Employment_request is created. Isn't it?
- Object takes more memory
- need more time to create it
- history data added after object creation isnt accessible

I want get related history data on method call. How to do it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire