php - Laravel 5: Access database data from within model -
i'm trying use laravel access data database. have setup model, works fine, i'm trying fetch data table creating method within model fetches data , sets property of model equal fetched data.
to fetch data, i'm trying use $this->id
property fetch row's id , use fetch data table (eg: someothermodel::where('other_id', '=', $this->id)->get();
)
however, none of data database seems have been fetched model @ point (eg: $this->id
null). constructor looks so:
public function __construct() { parent::__construct(); $this->other_data = $this->getotherdata(); }
is there way call $this->id
property database can use within model itself?
your syntax seemed me wrong:
someothermodel::where('other_id', '=', $this->id)->get();
can try this:
someothermodel::where('other_id', $this->id)->get();
reference: https://laravel.com/docs/5.1/eloquent#retrieving-single-models
i hope helps .
Comments
Post a Comment