2

Why is my freshly created laravel 9 project on PHP 8.0.8 showing an error by Visual Studio Code ?

VSCode shows this as an error :

return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());

enter image description here

anjanesh
  • 3,771
  • 7
  • 44
  • 58
  • try installing any Laravel coding assist plugins they usually help – apokryfos May 02 '22 at 13:16
  • 1
    Weird, what i notice is that you have **doble suggestion**, maybe you are using two extensions for php and that is bothering you? I recommend you to use PHP Inteliphense only -> https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client – Guille May 02 '22 at 19:19
  • In any case, you are able to use your app? is that "wrong sentence" stopping you to use the app? or it is working correctly? – Guille May 02 '22 at 19:21
  • Have you checked that VSCode knows you're using PHP 8.0? The [nullsafe operator](https://www.php.net/releases/8.0/en.php#nullsafe-operator) is new in that release, so if VSCode thinks you're using an older version, it would show that error. – IMSoP May 02 '22 at 21:23
  • [Please do not upload images of code/data/errors when asking a question.](//meta.stackoverflow.com/q/285551) – IMSoP May 02 '22 at 22:35
  • If you figured out the problem, don't forget to [answer your own question](https://stackoverflow.com/help/self-answer) so that it can be useful to other readers in future :) – IMSoP May 03 '22 at 08:04
  • I found out the reason why VSCode is showing an error - VSCode is detecting the default version of PHP on my macOS, PHP 7.1.33 and not my 8.0.8 installation - I am still looking for the solution - https://serverfault.com/q/1100013/39540 – anjanesh May 03 '22 at 09:59

1 Answers1

2

If you're using MAMP on a macOS which has PHP pre-installed like PHP 7.1.33 on macOS Mojave then change in Visual Studio Code settings, PHP > Validate: Executable Path - edit in settings.json :

"php.validate.executablePath": ""
or
"php.validate.executablePath": "/usr/bin/php"
to 
"php.validate.executablePath": "/Applications/MAMP/bin/php/php8.0.8/bin/php"

https://code.visualstudio.com/docs/languages/php

anjanesh
  • 3,771
  • 7
  • 44
  • 58