php - How to access object inside object in Laravel Blade file?
I have some data like below and I am trying to get an object inside the object in Laravel blade file usually it's supposed to work but here in the blade file in Laravel not working can you help me?
{
"id": 2,
"branch_id": 1,
"counselor_id": 3,
"universities": [
{
"id": 1,
"lead_id": 2,
"institute": 1,
"course": {
"id": 3,
"institute_id": 1,
"course_category_id": 4,
"course_level_id": 1,
"course_name": "BSc (Hons) Counselling",
"course_duration": "3",
"course_intake": "January, September",
"active": 1,
"created_at": "2021-06-10T06:40:45.000000Z",
"updated_at": "2021-06-10T06:40:45.000000Z",
"institute": {
"id": 1,
"represent_country_id": 1,
"institute_name": "University Name Here",
"campus_name": "London",
"active": 1,
"created_at": "2021-06-10T06:41:52.000000Z",
"updated_at": "2021-06-10T06:41:52.000000Z"
}
},
"created_at": null,
"updated_at": null
},
{
"id": 2,
"lead_id": 2,
"institute": 2,
"course": {
"id": 13,
"institute_id": 2,
"course_category_id": 10,
"course_level_id": 1,
"course_name": "BSc (Hons) Business and Events Management",
"course_duration": "3",
"course_intake": "January, May & September",
"active": 1,
"created_at": "2021-06-10T06:40:45.000000Z",
"updated_at": "2021-06-10T06:40:45.000000Z",
"institute": {
"id": 2,
"represent_country_id": 1,
"institute_name": "University Name Here",
"campus_name": "London",
"active": 1,
"created_at": "2021-06-10T06:41:52.000000Z",
"updated_at": "2021-06-10T06:41:52.000000Z"
}
},
"created_at": null,
"updated_at": null
}
]
}
blade.php
<div class="course-interest">
<ul>
@foreach ($applicant_infos['universities'] as $university)
<li>{{ $university['course']['course_name'] }}</li>
@endforeach
</ul>
</div>
it's not working. can anyone help me to how to access object inside object in laravel blade ?
Answer
Solution:
First check if $university->course
is not empty:
{{ $university->course ? $university->course->course_name : 'Course Not Found' }}
Answer
Solution:
You can access like below if you are passing model object
@foreach ($applicant_infos->universities as $university)
<li>{{ $university->course->course_name }}</li>
@endforeach
Updated.
you have to pass data to markdown like below
return $this->markdown('emails.application_email',['app_body'=>$this->app_body,'applicant_infos'=>$this->applicant_infos]);
Source