Thursday, August 4, 2016

eloquent relationships -- hasOne

1. create public function shape with hasOne relationships
class Member extends Model

    public function shape()
    {
       return $this->hasOne('App\Shape','part_id','part_id');
    }

2. Example with App\Member::with('shape')->find(1);
>>> App\Member::with('shape')->find(1);
=> App\Member {#751
     id: 1,
     part_id: "4882557",
     surname: "KRISHNAN",
     firstname: "KUMARESAN",
     email: "kumar@aeonmalaysia.com.my",
     created_at: "2016-08-04 10:19:56",
     updated_at: "2016-08-04 10:19:56",
     shape: App\Shape {#756
       id: 1,
       part_id: "4882557",
       match_score: "4.00",
       scales_num: "2.00",
       scales_cls: "22.00",
       created_at: "2016-08-04 10:20:05",
       updated_at: "2016-08-04 10:20:05",
     },
   }
>>>

No comments:

Post a Comment