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

frankhosaka's avatar

My best Livewire code, but it doen't work in Hostinger

The following code works on my Windows 11 / Apache setup. However, on Hostinger Ubuntu / Nginx, I receive the following message in the web console: https://meusite/livewire/update. It appears in the list when I run php artisan route:list, but I’m not sure whether Laravel can actually recognize this folder in Hostinger’s environment. At the very least, I can't see this folder, not even here on Windows.

I believe this is one of the best pieces of code I’ve ever written—it’s a shame it doesn’t work on Hostinger.

File: app/Livewire/Lteste.php

<?php
namespace App\Livewire;
use App\Models\tbprevisao;
use Illuminate\Support\Facades\DB;
use Livewire\Component;

class Lteste extends Component {

    public $id, $novoValor, $modal, $previsoes;

    function update() {
        $this->modal = false;
        $valor = deca($this->novoValor);
        tbprevisao::where('id', $this->id)->update(['valor' => $valor]);
        $this->previsoes = DB::table('tbprevisao')->join('tbw', 'tbprevisao.conta', 'tbw.conta')
            ->orderBy('tbprevisao.conta')->get();
    }

    function mount() {
        $this->previsoes = DB::table('tbprevisao')->join('tbw', 'tbprevisao.conta', 'tbw.conta')
            ->orderBy('tbprevisao.conta')->get();
    }

    function selecionado($id) {
        $this->id = $id;
        $this->modal = true;
    }
}

File: resources/views/livewire/lteste.blade.php

<div>
    <div class="flex odd:bg-gray-200">
        <div class="w-[50px] text-right">Account</div>
        <div class="w-[188px] px-2">Description</div>
        <div class="w-[130px] text-right">Forecast</div>
        <div class="w-[130px] text-right">Daily</div>
        <div class="w-[130px] text-right">Deviation</div>
    </div>
    @foreach($previsoes as $p)
        <div class="odd:bg-gray-200 flex" wire:click="selecionado({{ $p->id }})">
            <div class="w-[50px] text-right">{{$p->conta}}</div>
            <div class="w-[188px] px-2 truncate">{{$p->descricao}}</div>
            @if($modal && $id == $p->id)
                <div class="w-[130px] text-right">
                    <flux:input wire:model="novoValor" wire:change="update" size="xs" />
                </div>
            @else
                <div class="w-[130px] text-right">{{dec($p->valor)}}</div>
            @endif
            <div class="w-[130px] text-right">{{dec($p->fim)}}</div>
            <div class="w-[130px] text-right">
                {{dec(abs(round($p->valor - $p->fim + 0.0001,2)))}}
            </div>
        </div>
    @endforeach
</div>

0 likes
5 replies
Snapey's avatar

I receive the following message in the web console

What message?

frankhosaka's avatar

@Snapey 1 error update (https:\meusite\livewire\update). It is listed in php artisan list, but i don't know if Livewire can access this route in Hostinger environment. Livewire is very fun, but i don't know what to do when it alert that data is corrupted.

jlrdw's avatar

@frankhosaka What does the log show. Not whole log, just this error.

Are you setup correctly with main laravel one folder higher?

Many past discussions on correct setup.

frankhosaka's avatar
frankhosaka
OP
Best Answer
Level 2

Finally, I managed to work with Livewire's wire:model using MySQL. Copilot helped me a lot in creating the code without receiving the "Livewire encountered corrupted data" message on Hostinger:

Lteste.php

<?php
namespace App\Livewire;
use App\Models\tbprevisao;
use Livewire\Component;

class Lteste extends Component {
  
  public $previsao;
  
  function mount() {
      $this->previsao = tbprevisao::orderBy('conta')
        ->take(3)->get()->toArray();
    }
  
  function updated($propertyName) {
   	$previa=explode(".",$propertyName);
	$indice=$previa[1];
	$id=$this->previsao[$indice]['id'];
    $valor = data_get($this, $propertyName);
    tbprevisao::where('id', $id)
      ->update(['valor' => $valor]);     
    }
}

lteste.blade.php

<div class="w-[100px]">
    <flux:input wire:model="previsao.0.valor" wire:change="$refresh" />
    <flux:input wire:model="previsao.1.valor" wire:change="$refresh" />
    <flux:input wire:model="previsao.2.valor" wire:change="$refresh"  />  
    <pre>{{ print_r($previsao) }}</pre>
</div>

Please or to participate in this conversation.