1

Laravel - when I use compact() to send array of variables to view, my IDE (PHPStorm) doesn't see that variable is used and marks it as not used What to do to mark it used in this case ? I think that it would be better if compact was getting variable as a parameter, but not it's name as string

public function myControllerAction($param1, $param2)
    {
        $param3 = 'value';

        return view('mycomponent.myview', compact([
            'param1',
            'param2',
            'param3'
        ]));
    }

if I remove array symbols, it works! but I see it now like this: http://joxi.ru/bmoBLJxFxDLDVr.jpg

and it is not very readable

6
  • 1
    please show your code Commented May 21, 2018 at 11:59
  • 1
    Are you using Laravel Plugin? Did you activate it? Commented May 21, 2018 at 12:02
  • I've edited question, added a code example and that it is right when I send an array of variables Commented May 21, 2018 at 12:13
  • 1
    You have used array in compact compact ([ 'param1', 'param2', 'param3' ]) So just write compact('param1','param2','param3') Commented May 21, 2018 at 12:20
  • 1
    you can turn the hints off altogether, by navigating to Editor | General | Appearance and deselecting Show parameter name hints. Commented May 21, 2018 at 12:29

2 Answers 2

5

Remove that array symbol, compact will handle single variable, array, even multidimensional array

 public function myControllerAction($param1, $param2)
        {
            $param3 = 'value';

            return view('mycomponent.myview', compact('param1','param2','param3'));
        }
Sign up to request clarification or add additional context in comments.

Comments

0

You should try this:

public function myControllerAction($param1, $param2)
{
    $param3 = 'value';

    return view('mycomponent.myview', compact('param1','param2','param3'));


    OR


    return view('mycomponent.myview', ['param1'=>$param1,'param2'=>$param2,'param3'=>$param3]);
}

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.