#10749·livewire

[4.x] Encrypted Eloquent attributes are validated using the raw ciphertext with legacy model binding

Author: sfortier-sjsrCreated Sep 24, 2026Updated Sep 24, 2026

Livewire version

v4.4.2

Laravel version

v13.26.1

PHP version

8.5.9

Browser and operating system

Edge on Windows

Describe the issue you're experiencing

After upgrading Livewire from v4.4.1 to v4.4.2, validation of a nested Eloquent model property with an encrypted cast uses the raw encrypted database attribute instead of the decrypted value submitted by the user.

This causes normal validation rules such as max:12 to fail unexpectedly. The issue is especially confusing because reading the property from the model returns the expected decrypted value, and strlen() reports the expected length.

In my case I had a phone number field with [ 'min:12','max:12'] validation rules because this is what I expect.

Im using livewire model binding : appointment.phone_number inside my livewire component. In the model, the phone_number is casted as « encrypted ». Before this version the validation was working but now it always say that the phone number can't have more than 12 characters.

I suspect that the problem has been introduced in this PR but I am not sure : https://github.com/livewire/livewire/pull/10559

Code snippets to reproduce the issue

1. Enable legacy model binding

In config/livewire.php:

php
<?php

return [
    'legacy_model_binding' => true,
];

2. Create the model

php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Contact extends Model
{
    protected $fillable = [
        'phone',
    ];

    protected function casts(): array
    {
        return [
            'phone' => 'encrypted',
        ];
    }
}

3. Create the migration

php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('contacts', function (Blueprint $table) {
            $table->id();
            $table->text('phone')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('contacts');
    }
};

4. Create the Livewire component

php
<?php

namespace App\Livewire;

use App\Models\Contact;
use Livewire\Component;

class EncryptedPhoneForm extends Component
{
    public Contact $contact;

    public function mount(): void
    {
        $this->contact = Contact::create([
            'phone' => null,
        ]);
    }

    protected function rules(): array
    {
        return [
            'contact.phone' => [
                'nullable',
                'min:12',
                'max:12',
            ],
        ];
    }

    public function save(): void
    {
        $this->validate();
    }

    public function render()
    {
        return view('livewire.encrypted-phone-form');
    }
}

5. Create the Blade view

blade
<div>
    <form wire:submit="save">
        <input
            wire:model="contact.phone"
            type="text"
            placeholder="XXX XXX-XXXX"
        >

        <button type="submit">Save</button>
    </form>

    @error('contact.phone')
        <p>{{ $message }}</p>
    @enderror
</div>

6. Add a route

php
use App\Livewire\EncryptedPhoneForm;
use Illuminate\Support\Facades\Route;

Route::get('/encrypted-phone-form', EncryptedPhoneForm::class);

Steps to reproduce

  1. Install Livewire v4.4.2.
  2. Run the migration.
  3. Open /encrypted-phone-form.
  4. Enter 111 111-1111 in the phone field.
  5. Submit the form.
  6. Observe that the max:12 validation rule fails.
  7. Temporarily downgrade Livewire to v4.4.1 and repeat the same steps.
  8. Observe that the validation passes with v4.4.1.

Screenshots/screen recordings

No response

How do you expect it to work?

Before the update, the validation was passing since I guess that the not encrypted value was used for validation but now it seems like the encrypted value is used for the validation check.

I find it odd that a minor version upgrade of the framework broke my form validation

Please confirm (incomplete submissions will not be addressed)

  • I have provided easy and step-by-step instructions to reproduce the bug.
  • I have provided code samples as text and NOT images.
  • I understand my bug report will be removed if I haven't met the criteria above.