0

Laravel v 9.11

Livewire v 2.5

vscode v 1.67.2

intelephense v 1.8.2

In laravel project i have a livewire component with a search function

model Department:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Department extends Model
{
  public static function search($search)
  {
    return empty($search)
      ? static::query()
      : static::query()
      ->where('department_name', 'like', '%' . $search . '%');
  }
}

livewire: DepartmentWire

<?php

namespace App\Http\Livewire\Admin\Departments;

use App\Models\Department;

class DepartmentWire extends Component
{

  public $search = '';

  public function read()
  {
    $data = [
      'departments' => Department::search($this->search) //--> error here
        ->with('users')
        ->withCount('users')
        ->orderBy('department_name')
        ->paginate(10),
    ];
    return $data;
  }


  public function render()
  {
    return view('livewire.admin.departments.department-wire', $this->read());
  }
}

every thing works fine except that intelephense gives me an error

Expected type 'object'. Found 'void'.intelephense(1006)

John Deck
  • 787
  • 1
  • 12
  • 27
  • You should create a scope instead https://laravel.com/docs/9.x/eloquent#query-scopes – Qirel May 28 '22 at 13:20
  • 1
    This is also just a editor thing, has nothing to do with Laravel or Livewire directly – Qirel May 28 '22 at 13:20
  • How to use scope in my case !? .. i tried but it gives me error .... Object of class Illuminate\Database\Eloquent\Builder could not be converted to string – John Deck May 28 '22 at 14:59
  • 1
    There's examples in the docs I linked https://laravel.com/docs/9.x/eloquent#dynamic-scopes – Qirel May 28 '22 at 16:01

1 Answers1

0

problem solved when downgrade intelephense to version 1.3.11

John Deck
  • 787
  • 1
  • 12
  • 27