7 months ago

Upgrading from 5.8 to 6.7.2 made eloquent union function to cast an integer to a string

Posted 7 months ago by cuartas15

I ugraded my app's laravel version to the latest (among other composer dependencies, including php from 7.1.2 to 7.2) and now union is doing some weird stuff with my data:

    $appointmentList = Appointment::select('id', DB::raw('null as appointment_id'), 'office_id', 'patient_id', 'date', 'time', 'minutes', 'selected_entity', 'available', 'locked', 'active', 'description', DB::raw('1 as isAppointment'))
        ->where('office_id', auth()->user()->office_id)
        ->where('date', $formatDate->toDateString())
        ->where('active', '1');

    $revisionList = Revision::select('id', 'appointment_id', 'office_id', 'patient_id', 'date', 'time', 'minutes', 'selected_entity', 'available', 'locked', 'active', 'description', DB::raw('0 as isAppointment'))
        ->where('office_id', auth()->user()->office_id)
        ->where('date', $formatDate->toDateString())
        ->where('active', '1');

    $appointmentRevisionList = $appointmentList->union($revisionList)


    return Response::json([
        'success' => true,
        'data' => $appointmentRevisionList,
    ], 200);

note the Log line, that is giving me a string instead of an int in appointment_id (which is a BIGINT on MySql) if I just log this:


Now it gives me the correct data type. So basically the combination of union and apparently setting the value to null on $appointmentList is giving me this weird behaviour after I upgraded to laravel 6.7.2. I completely discard the PHP upgrade because my current DO production server is already using PHP 7.3, but it's still using 5.8 for Laravel. This is happening as of right now, on my local environment.

I want to know how to fix this honestly.

Thank you.

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