php - Laravel one-to-one relationship giving errors -


im trying implement one-to-one relationship, im calling 'command' , keep getting undefined property error when viewing record in relationship.

in model have following

public function preferences() {     return $this->hasone('app\websitepreferences', 'id', 'website_id'); } 

then im calling such

    $websites = website::where('active', 1)->get();      foreach ($websites $website) {          var_dump($website->preferences()->status);      } 

the exact error follows

undefined property: illuminate\database\eloquent\relations\hasone::$status  

if var_dump($website) returns values in table, not ones in websitepreferences table associated 'website'

i have few other one-to-one relationships , work fine.

any appreciated.

when call relationship method, returns querybuilder instance. allow keep chaining where, , on.

instead should call attribute:

$website->preferences->status  

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -