[TriLUG] Fighting a Laravel error. Help?

Brian McCullough via TriLUG trilug at trilug.org
Tue Jan 24 18:47:00 EST 2023


I have been running in circles for far too long and finally got well
past the point where I should have shouted for help.


I am getting an error from Laravel and I can't seem to see what to do to
fix it.   I'm sure that it is something obvious and that I am just
blind.



The error is "Object of class Collection could not be converted to int."

This error occurs down near the bottom of the code below, the IF with
"$personData->person_type_id".   All of my debugging dumps say that the
value is actually an INT.


=====================================================================


        $peopleData = DB::connection('mysql_ems')
            ->table('people')
            ->whereNull('archived_at' )
            ->select( 'id', 'first_name', 'last_name', 'person_type_id',
'archived_at' )
            ->get()
            ->toArray();

        foreach ($peopleData as $personData) {

                echo "\nPersonType: " .
var_export($personData->person_type_id, true) . "\nPerson: " .
var_export($personData, true) . "\n\n";

                echo "PersonType: " . print_r(
$personData->person_type_id, true ) . "\n\n" ;

                if ($personData->person_type_id == $emsStudentType) {
                    $peopleStudents[] = [
                        'ems' => $personData->id,
                        'first' => $personData->first_name,
                        'last' => $personData->last_name,
                        'archived_at' => $personData->archived_at,
                        'tms' => $personID->id
                    ];
            	}
            }
        }


=======================================================================




More information about the TriLUG mailing list