I want to use some data in profile page that I successfully can pass those data to the view
return view('pages.profile' , compact('data' , 'faculty' , 'scores' , 'sub' , 'finance_r'));
But when I want to use nested for each to print "sub" data in to the foreach base on the "data" section I got an error
Trying to get property 'id' of non-object (View:
The simplest thing that I want to do
@foreach ($data as $data)
@foreach ($sub as $sub)
{{ $sub->id }}
@endforeach
@endforeach
I find this on the laravel Docs but it doesn't work
@foreach ($users as $user)
@foreach ($user->posts as $post)
@if ($loop->parent->first)
This is first iteration of the parent loop.
@endif
@endforeach
@endforeach
How we can able to use a foreach in side the other foreach?
NOTE : all data that I pass to view are Object. My sub data is
Collection {#865 ▼
#items: array:8 [▼
0 => Subject {#856 ▼
#table: "subject"
+timestamps: false
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:5 [▼
"id" => 8
"name" => "پروگرامینگ"
"number_of_credites" => 5
"semester_id" => 1
"faculty_id" => 2
]
#original: array:5 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
#hidden: []
#visible: []
#fillable: []
#guarded: array:1 [▶]
}
1 => Subject {#857 ▶}
2 => Subject {#858 ▶}
And my data
Collection {#848 ▼
#items: array:3 [▼
0 => Scores {#844 ▼
#table: "scores"
+timestampes: false
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:6 [▼
"id" => 4
"subject_id" => 15
"score" => 100
"scores_student_details_id" => 7
"created_at" => "2018-04-09 15:02:24"
"updated_at" => "2018-04-09 15:02:21"
I actually want to print sub according to the "faculty_id" => 1
$usersfor foreach. Have you send it to view from controller?$loopvariable from? Are you sure this is where you're throwing your error? Within your code you provided you don't seem to be attempting to access anidproperty anywhere.