Laravel 5 + Eloquent toJson / toArray causes strange segmentation errors

I hate answering my question, so maybe you can help me find what is fixed.

I have some eloquent models that belong together, and I installed them through an association like this. Everything is fine.

This process, unfortunately, makes $ device unstable. Below you can see that individual values ​​are available, but any form of jsonification destroys the server without errors.

$device = $truck->device;
if(is_null($device) || empty($device)) {
    $device = new Devices;
}
$device->truck()->associate($truck);
$device->fleet()->associate($fleet);
$device->serial = $device_input['serial'];

$device->save();
$truck->device()->associate($device);
$truck->save();

error_log( $device->id );               //OK
error_log( $truck->device->id );        //OK
error_log( $device->toJson() );         //ERROR SEGMENTATION FAULT
error_log( $truck->toArray() );         //ERROR SEGMENTATION FAULT
error_log( $truck->device->toJson() );  //ERROR SEGMENTATION FAULT
error_log( $truck->device->toArray() ); //ERROR SEGMENTATION FAULT
error_log( json_encode($device) );             //ERROR SEGMENTATION FAULT
error_log( json_encode($truck->device) );      //ERROR SEGMENTATION FAULT
+4
source share
1 answer

Laravel does not handle the error correctly.

. , , , , , .

if:

if(is_null($device) || empty($device)) {
    $device = new Devices;
    $device->truck()->associate($truck);
    $device->fleet()->associate($fleet);
}

, . , , , .

, , json. - - laravel ,

+3

All Articles