skip to Main Content

i have a search feature like this, when you click on the row, it will added to the list.

enter image description here

i’ve been trying to solve this about 3 days now. so i have the same version of the app in my local and my hosting. but i don’t know why in the hosting will show error like this

enter image description here

while in my local works just fine

enter image description here

here is my code

on the resources/views/livewire/kasir/query-barang.blade.php

<div class="table-row cursor-pointer hover:bg-slate-700 hover:text-white"
                    wire:click="submit({{$br->barcode}})">

submit function on app/Http/Livewire/Kasir/QueryBarang.php

public function submit($barcode)
    {
        $this->emit('selectBarang', $barcode);
        $this->closeModal();
        $this->reset();
    }

and then the emit will listen by app/Http/Livewire/Kasir/SearchBarang.php

protected $listeners = [
        'selectBarang' => 'selectBarang'
    ];

public function selectBarang($barcode)
    {
        $this->barcode = $barcode;
        $this->submit();
    }

 public function submit()
    {
        /* Mengecek apakah barcode berbentuk numeric */
        if (is_numeric($this->barcode)) {
            /* jika true, maka akan menambahkan barang */
            $this->barang = Barang::where('barcode', $this->barcode)->first();
            $this->createOrUpdate();
        } else {
            /* Jika False maka akan mencari dan menampilkan Modal */
            $this->queryBarang($this->barcode);
            $this->reset('barcode');
        }
    }

public function createOrUpdate()
    {
        $checkBarangDalamList = TransaksiJualDetail::where('transaksi_jual_id', $this->transaksiJual)->where('barang_id', $this->barang->id)->first();
        if ($checkBarangDalamList == null) {
            $this->addNewStuff();
            $this->addTotal();
            $this->reset('barcode');
            $this->emit('storeNewList', $this->transaksiJual);
        } else {
            $this->addQuantity();
            $this->addTotal();
            $this->reset('barcode');
            $this->emit('storeNewList', $this->transaksiJual);
        }
    }

in the error as shown above, it clearly say that $this->barang is null . when i try to diedump $this->barcode on the submit function, it showing clearly what is the barcode
enter image description here

but, when i try to diedump $this->barang on the submit function it will showing me null value

enter image description here

What is wrong with my code ?
Thanks for the answer

2

Answers


  1. Chosen as BEST ANSWER

    after trying to fix this for 3 days, finally i got something that work. so i have to change the query from this

    $this->barang = Barang::where('barcode', $this->barcode)->first();
    

    to this

    $this->barang = Barang::all()->where('barcode', $this->barcode)->first();
    

    if you asking me what is the different, tbh i don't know. and i don't know either why it works.


  2. Hypothesis: Two of your statements make me suspicious that it’s a data issue, not code.

    1. In the submit function where $this->barcode has a value but $this->barang is null. The only operation is database query.

      $this->barang = Barang::where(‘barcode’, $this->barcode)->first();

    2. The issue happens in HOSTING while working on LOCAL. I assume your HOSTING environment and LOCAL environment use different databases.

    Propose Actions: Please check whether the data is available in HOSTING as same as LOCAL.
    You can use firstOrFail() collection instead of first() to detect and handle this error.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search