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

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. Commented Sep 16, 2019 at 19:23
  • We pass all of them form controller, work on host and local correctly this error just in PhpStorm Commented Sep 16, 2019 at 19:45
  • 3
    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. Commented Sep 16, 2019 at 23:57
  • in v2017 or v2016 not exist this problems, and in this version this variables without error in {{ }} and just take error in @php Commented Sep 17, 2019 at 16:08
  • 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). Commented Sep 18, 2019 at 16:30

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

2

Try this in top of your view:

<?php
/**
 * @var object $property
 */
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.