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

douggough's avatar

Livewire can't access component?

I've created a resource with a view page. When I visit the page I get an error saying Undefined variable $jobStatus. The error is generated from the blade view. I've gone over the code and can't see the error. It's probably something simple but I'm missing it. Any help is appreciated.

On the view page I'm calling a livewire component like this:

class ViewPanImport extends ViewRecord
{
    protected static string $resource = PanImportResource::class;

    protected static string $view = 'livewire.pan-import-progress';

}

This is the view at the path resources/views/livewire/pan-import-progress.blade.php

<div wire:poll.5s="checkJobStatus">
    @if ($jobStatus === 0)
        <p>The import is in progress.</p>
        <x-filament::loading-indicator class="h-10 w-10 text-primary-500" />
    @elseif ($jobStatus === 1)
        <p>The import is finished.</p>
    @endif
</div>

And this is the component at app/livewire/PanImportProgress.php

0 likes
2 replies
LaryAI's avatar
Level 58

The issue you're encountering with the Undefined variable $jobStatus error in your Livewire component is likely due to the way the jobStatus variable is being passed to the Blade view. Let's go through the solution step-by-step:

  1. Ensure Proper Data Binding: Make sure that the jobStatus property is correctly initialized and updated in your Livewire component. It seems like you are doing this correctly in the mount and checkJobStatus methods.

  2. Check the Blade View: In your Blade view, you are using the jobStatus variable directly. Since you are passing it from the Livewire component, ensure that the variable is correctly being passed to the view. Your render method seems to be doing this correctly.

  3. Verify the Component Registration: Ensure that your Livewire component is correctly registered and used in your Blade file. You should be using the Livewire component tag in your Blade view like this:

    @livewire('pan-import-progress', ['record' => $record])
    

    Make sure that the record variable is being passed correctly to the component.

  4. Check for Typos and Syntax Errors: Double-check your code for any typos or syntax errors, especially in the Blade view and the Livewire component.

  5. Debugging: Add some debugging statements to ensure that the jobStatus is being set correctly. You can use dd($this->jobStatus); in your checkJobStatus method to see if the value is being set as expected.

  6. Livewire Version: Ensure that you are using a compatible version of Livewire with your Laravel application. Sometimes, version mismatches can cause unexpected behavior.

Here's a quick checklist to ensure everything is set up correctly:

  • Livewire Component: Ensure the component is registered and used correctly.
  • Data Binding: Ensure jobStatus is correctly initialized and updated.
  • Blade View: Ensure the variable is passed and used correctly in the view.
  • Debugging: Use debugging tools to verify the flow of data.

If all these steps are correctly followed and the issue persists, consider checking the Livewire documentation or forums for any known issues related to your specific version.

douggough's avatar

I figured it out. I wasn't passing the record into the livewire component.

Please or to participate in this conversation.