lundi 19 novembre 2018

Manipulating data within an object

Hi I am new to Laravel and php. In my database each student has three marks on each subject and I need to retrieve them and send to the view the average mark for each student. I tried doing it like below, but the returned value is an object (e.g. [5,4,3]) and it doesn't let me count the average. Please advise how I can operate with data within the object.

$students = Student::all();
foreach ($students as $student){
$mathPoints = Point:: where('subject_id', 1)
->where('student_id', $student->id)
->pluck('points');

I tried turning it into an array by (array) method, but I couldn't calculate the sum of values with array_sum after.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire