[TriLUG] Fighting a Laravel error. Help?

Bill Farrow via TriLUG trilug at trilug.org
Wed Jan 25 19:30:43 EST 2023


Brian, I hope you don't mind but I asked ChatGPT your question and the
response is below. I would be really interested if this helps you.


The error message you're seeing is likely being caused by this line:

'tms' => $personID->id

It seems that you are trying to access the id property of an object that is
not set or is null. This line of code should likely be changed to:

'tms' => $personData->id

As you are trying to access the id property of the $personData object which
is the current iteration in the foreach loop.

Also, it's important to note that the toArray() function returns an array
of arrays and not an array of objects, so you'll need to access the
properties of the current iteration using array notation.

foreach ($peopleData as $personData) {
    echo "\nPersonType: " . var_export($personData['person_type_id'], true)
. "\nPerson: " . var_export($personData, 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' => $personData['id']
        ];
    }
}
It is also important to check if the $emsStudentType variable is an integer
before comparing it to $personData['person_type_id']





Bill


On Wed, Jan 25, 2023 at 2:21 PM Brian McCullough via TriLUG <
trilug at trilug.org> wrote:

> On Wed, Jan 25, 2023 at 01:25:23PM -0500, Triangle Linux Users Group
> discussion list wrote:
> > relatedly (and I'm a Perl guy, not a Laravel guy so this is a shot in the
> > dark), can you explicitly cast the person id to an int before the
> equality
> > comparison?
>
> Thank you both.
>
> Yes, I tried the cast with no effect.
>
> I didn't try actual numbers.  Thanks.  I will try that.
>
>
> > William Sutton
> >
> > On Wed, 25 Jan 2023, Scott Lambdin via TriLUG wrote:
> >
> > > My instinct is to replace the comparison terms one at a time with a
> literal
> > > int and see what happens.
> > >
>
>
> Brian
>
> --
> This message was sent to: Bill Farrow <bill.farrow at gmail.com>
> To unsubscribe, send a blank message to trilug-leave at trilug.org from that
> address.
> TriLUG mailing list : https://www.trilug.org/mailman/listinfo/trilug
> Unsubscribe or edit options on the web  :
> https://www.trilug.org/mailman/options/trilug/bill.farrow%40gmail.com
> Welcome to TriLUG: https://trilug.org/welcome


More information about the TriLUG mailing list