Skip to content

Error serialised with php8. 4 HooksΒ #57357

@Fulliton

Description

@Fulliton

Laravel Version

12.32.5

PHP Version

8.4

Database Driver & Version

Mariadb 11, redis latest

Description

There is a bug in Laravel

If new get-set Hooks are used in the model, an error pops up when executing queues or Events using redis.

I use this bug fix in my work projects. The solution to get away from Attributes is to get away from using magic methods for simple calculations.

Error message: "Failed to serialize job of type [Illuminate\Events\CallQueuedListener]: serialize(): "full_name" returned as member variable from __sleep() but does not exist"

Code in Model

<?php

namespace App\Models;

use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Prunable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;

final class Client extends Authenticatable
{
    use HasApiTokens;
    use HasFactory;
    use Notifiable;
    use Prunable;
    use SoftDeletes;

    protected $connection = 'mariadb';

    protected $fillable = [
        'first_name',
        'last_name',
        'middle_name',
    ];

    public string $full_name {
        get => "{$this->last_name} {$this->first_name} {$this->middle_name}";
    }
    ...
    
}

I'm using this fix in Laravel version 12.32.5.

Wtf @taylorotwell ???

Pls view commit Fulliton@95d7bc1

Steps To Reproduce

Fulliton@95d7bc1

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions