Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thebigk's avatar
Level 13

Livewire: How do I mask the classname that component exposes?

I'm new to Livewire. I want to know if there's a way to mask the classname that component exposes? For example, the wire:snapshot exposes the model information (App\Models\Post) etc.

I remember reading about some mechanism in Livewire that allows masking the sensitive information? AFAIK, there's a way to alter the class name with something vague; like Post can be rendered as 'SomePost' in the wire snapshot.

I'm scouting the entire documentation; but can't find it. I'd really appreciate your help.

0 likes
4 replies
thebigk's avatar
Level 13

Looking for a real human, Laravel user to help me out.

thebigk's avatar
Level 13

Update. Found the solution:

<?php
 
namespace App\Providers;
 
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Relations\Relation;
 
class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Relation::morphMap([
            'post' => 'App\Models\Post',
        ]);
    }
}

I want to know if there's a way to hide Model IDs as well?

martinbean's avatar

@thebigk Why are you using Livewire in the first place if you don’t like that it exposes class names and database identifiers?

The golden rule of client-side development is, if you don’t want the user to see it then don’t send it in the first place. It seems Livewire may not be suitable to your use case.

Snapey's avatar

Share the data with the view as an array or discrete properties rather than model objects. If you share the entire model you risk exposing more data than you intended, never mind the class name.

1 like

Please or to participate in this conversation.