我有一個變量傳遞雖然我在我的視圖控制器: 名字是$其他如何laravel訪問集合的單值屬性5
當我做一個foreach和打印它像
@foreach($others as $other)
{{ $other }}
@endforeach
輸出爲:
[{"employeeID":"9125123981003","email":"[email protected]","fullName":"Pranshu Jain"}] [{"employeeID":"45755757577","email":"[email protected]","fullName":"Pranshu Jain"}]
我想要的就是訪問從這些單屬性?他們是收藏品嗎?
我試過這樣
@foreach($others as $other)
{{ $other->email }}
@endforeach
這是我如何得到這個$others
填充:
public function show($id)
{
$this->data['leave_application'] = Attendance::find($id);
$date_applied_on = $this->data['leave_application']->date;
$emp_id = $this->data['leave_application']->employeeID;
$other_on_leave = Attendance::where('date', '=', $date_applied_on)->get();
$employees_on_leave = [];
foreach($other_on_leave as $others) {
if($emp_id != $others->employeeID) {
$emptyarray = Employee::where('employeeID', '=', $others->employeeID)->get(array('employeeID','email','fullName'));
$employees_on_leave[] = $emptyarray;
}
}
$this->data['others'] = $employees_on_leave;
return view('admin.leave_applications.show', $this->data);
}
但它不工作。請幫助和引導一點點。我熟悉數組和對象。我曾經與他們做得很好。但這似乎並不複雜。
,如果我做DD($等),然後我得到
array:2 [▼
0 => Collection {#344 ▼
#items: array:1 [▼
0 => Employee {#345 ▼
#guarded: array:1 [▼
0 => "id"
]
#hidden: array:1 [▼
0 => "password"
]
#connection: null
#table: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:3 [▶]
#original: array:3 [▶]
#relations: []
#visible: []
#appends: []
#fillable: []
#dates: []
#dateFormat: null
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
+wasRecentlyCreated: false
}
]
}
1 => Collection {#346 ▼
#items: array:1 [▼
0 => Employee {#347 ▼
#guarded: array:1 [▶]
#hidden: array:1 [▶]
#connection: null
#table: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:3 [▶]
#original: array:3 [▶]
#relations: []
#visible: []
#appends: []
#fillable: []
#dates: []
#dateFormat: null
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
+wasRecentlyCreated: false
}
]
}
]
** $ others **的類型是什麼,它是一個集合嗎?你的控制器中的「dd($ others)」可以告訴你。 –
請寫下你的控制器函數返回這個視圖。 –
@MustafaEhsan請檢查 –