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

mikromike's avatar

string or Carbon object wit livewire, which one ?

Hello

I try to send Carbon date string during mount to livewire parent component.

I have child component @livewire('counting.action-date').

during mount, it will pickup carbon:now() and should emitUp to parant component.

    public function mount()
     {

       $this->actionDate = Carbon::now()
                      // ->format('Y-m-d');
                  ->toDateString();
       $this->sendActionDate($this->actionDate);
     }

 public function sendActionDate($value)
    {
       $this->validate([
        'actionDate' => 'required',
     ]);
      $this->actionDate =  $value;
      $this->emitUp('savedDateUpdated', $this->actionDate);
   }

** if I dump $this->emitUp('savedDateUpdated', $this->actionDate);

  • it says null // app\Http\Livewire\Counting\ActionDate.php:29

** if I dump $this->actionDate or $value

  • "2023-01-10" // app\Http\Livewire\Counting\ActionDate.php:29

Parent component:

    public function savedDateUpdated($value)
    {
     $this->saveDate = $value;
   }
  • if I delete exist value from input element and add date manually, it will send new value to parent.

** input element is blade component:

   <x-date-input wire:model="actionDate">
     <x-slot name="type">
       date
  </x-slot>
  <x-slot name="name">
    action_date
 </x-slot>
<x-slot name="placeholder">
     Laskun Kirjauspäivä
 </x-slot>

I am stuck, how fix this ???

thanks advice ....Mika.

0 likes
1 reply
mikromike's avatar
mikromike
OP
Best Answer
Level 29

According https://github.com/livewire/livewire/issues/598

 "@itsmemanoj emit won't work in the mount function or render function (during the first load) as 
 Livewire's  javascript isn't running yet. But it will work in the render function on subsequent requests."

So Closed.

Please or to participate in this conversation.