jhutto

Add an array item to collection array in controller

Posted 7 months ago by jhutto

I have three database fields that I need to add together and place in view. I'm using a ajax call to pull the data. I'm pulling the line of data from the database in the first collection that is created called Tuitions.

Then I"m adding the fields together in $TuitionTotal

Now I need to put the $TuitionTotal - Key 'TuitionTotal' and Value "140" back into the collection array[0] But I have not been able to find anything that works.

$Tuitions = Tuition::where('id', $id)->get();

$TuitionTotal = $Tuitions[0]->ClassFee + $Tuitions[0]->HomeOfficeFee + $Tuitions[0]->MaterialsFee ;

Please sign in or create an account to participate in this conversation.