PhpStorm take undefined variable error for passes variables to view
Asked Answered
V

2

5

I'm using last version of PhpStorm v2019.2. In this version take Undefined Variable for all passed variable to view from controller

@foreach( $specifications as $specification )
     @php
         $type_spec = $specification->types->where('id',$property->type_id);
     @endphp
@endforeach

or other error picture in PhpStorm, we passed $property from controller and code work correctly

Or other error

Vacillatory answered 16/9, 2019 at 16:58 Comment(5)
It is not very clear where you are having issues. Do you have any errors? Is you loop not looping properly? Are you passing specifications properly from the controller? Give us the code where you return this view.Crackbrain
We pass all of them form controller, work on host and local correctly this error just in PhpStormVacillatory
IDE does not know what variables come into what view. If you need them to be "known", use PHPDoc @var and declare (so IDE knows that such variable indeed exists and what type that is/what methods can be called). IDE does not provide any special support for Laravel framework (it's done by 3rd party plugin), but IDE provides plugin for Blade files.Pomfret
in v2017 or v2016 not exist this problems, and in this version this variables without error in {{ }} and just take error in @phpVacillatory
IDE treats content inside @php as if it would be normal valid <?php ... ?> block. The stuff inside {{ }} can be anything, so it's not checked that much (as variables may be coming from anywhere).Pomfret
B
10

Just add /* @var $your-variable */ to the same @php block

 @php
     /* @var $property */
     $property->load("rejects")
 @endphp

OR

On top of your fileName.blade.php

 <?php /* @var \App\Models\YourClassName $property */ ?>

Tested with v2019.1.3 + Laravel 8.x

Bracteate answered 28/12, 2020 at 8:45 Comment(0)
V
2

Try this in top of your view:

<?php
/**
 * @var object $property
 */
?>
Voltameter answered 28/12, 2020 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.