Hello! I'm getting a false positive warning in my Laravel project when using Livewire components. The editor warns about a call to an unknown method on the View object, although this is the official and correct way to define layouts in Livewire.
The Warning: Call to unknown method: Illuminate\Contracts\View\View::layout()
Code Example:
<?php
namespace App\Livewire;
use Livewire\Component;
class MyComponent extends Component
{
public function render()
{
// The view() helper returns 'Illuminate\Contracts\View\View'
// Livewire dynamically adds the 'layout()' and 'title()' macros to this View object.
return view('livewire.my-component')->layout('components.layouts.app');
}
}
Context & Cause: Livewire extends Laravel's Illuminate\Contracts\View\View dynamically via Macros at runtime to chain layout and title methods. Because of this dynamic injection, the static analyzer flags layout() as an unknown method.
Currently, the only way to bypass this in the IDE is by casting the view to mixed via DocBlocks:
/** @var mixed $view */
$view = view('livewire.my-component');
return $view->layout('components.layouts.app');
Suggestion: It would be great if the PHP Tools extension could provide built-in knowledge/stubs for Laravel Livewire's View macros (layout() and title()) so we don't need to obscure our code with @var mixed or ignore the warnings globally.