Debug School

rakesh kumar
rakesh kumar

Posted on

Livewire:Property [$users_id] not found on component

yesterday i found error where is my code

 public function render()
        log::info("here render data");

        $socialUrls = DB::connection('payments')
                        ->where('user_id', $this->users_id)

        // Check if socialUrls is empty
        $isEmpty = $socialUrls->isEmpty();  // This returns true if the collection is empty

        return view('', [
            'socialUrls' => $socialUrls,
            'isEmpty' => $isEmpty
Enter fullscreen mode Exit fullscreen mode


Issue:The error message "Property [$users_id] not found on component: []" suggests that the property users_id is not properly initialized or accessible within your Livewire component. This could be because the property is either not declared or not assigned any value before it's used in the query. Here's how you can address this issue:

  1. Declare the Property: Make sure that the property users_id is declared within your Livewire component.
  2. Ensure Property Initialization: Ensure that users_id is set to an appropriate value before the component tries to access it in the database query .
public $users_id; // Declare the property

    public function mount($users_id = null) // You can pass the user ID when mounting the component
        // Initialize users_id, for example, from the authenticated user or passed parameter
        $this->users_id = $users_id ?? auth()->id(); // Fallback to authenticated user ID if not provided
Enter fullscreen mode Exit fullscreen mode

now i run code it works perfectly

Top comments (0)