Level 63
Have you tried this ?
@if ($event)
@if ($editing)
<x-text-input wire:model="event.headline" class="block mt-1 w-full" type="text" />
@else
{{ $event->headline }}
@endif
@endif
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
when I'm trying to use my Eloquent Model for the data binding with wire:model I'm getting an error in the console
Uncaught TypeError: Cannot read properties of null (headline)
My Livewire Component
<?php
namespace App\Livewire\Events;
use App\Models\Event;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Livewire\Component;
class EventView extends Component
{
public $id;
public array|null|Builder|Collection|Model $event;
public string $currentTab;
public bool $editing;
public string $textarea;
public function mount($id)
{
$this->id = $id;
$this->event = Event::with(['user', 'invitees.user'])->findOrFail($this->id);
$this->currentTab = 'home';
$this->editing = true;
$this->headline= $this->event->headline;
}
public function render()
{
return view('livewire.pages.event.event-view')
->layout('layouts.app')
;
}
public function gotoTab(string $tab = 'home'): void
{
$this->currentTab = $tab;
}
public function setEditing(): void
{
$this->editing = true;
}
public function updateEvent(): void
{
dd($this->event->text);
}
}
And my blade file (throws the error)
@if($editing)
<x-text-input wire:model="event.headline" class="block mt-1 w-full" type="text" />
@else
{{ $event->headline }}
@endif
But when I'm using the $headline which i also set in the mount() it works
Anyone got any ideas? Thanks
Please or to participate in this conversation.