php - L5 | Relationship Tinker Query -


i've setup 1 many relationship following models job , steps. job can have many steps, , step belongs job. when go query relation job::with('steps')->find(1), results displayed expected collection

<mariasapp\job #000000002b07ae180000000036b76e17> {        id: 1,        number: 59221,        customer_id: 5,        user_id: 17,        created_at: "2015-03-24 01:32:20",        updated_at: "2015-03-24 01:32:20",        steps: <illuminate\database\eloquent\collection #000000002b07ae070000000036b76e17> [            <mariasapp\step #000000002b07ae7b0000000036b76e17> {                id: 37,                job_id: 1,                body: "eligendi reiciendis ratione labore sed.",                created_at: "2015-03-24 01:32:21",                updated_at: "2015-03-24 01:32:21"            }        ]    } 

but when run job::with('steps')->find(1)->body response null. there way me pull body relation?

i assume you're trying body steps collection. need specify step you're trying work with. either use first one

job::with('steps')->find(1)->steps->first()->body

or loop through them

$steps= job::with('steps')->find(1)->steps->all();  foreach($steps $step){     echo step->body;  } 

or cycle through many jobs , first step of each one:

$jobs = job::with('steps')->get();  foreach($jobs $job){   echo $jobs->steps->first()->body; } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -