Laravel 9 + PHP 8.0.8 in VSCode shows syntax error, unexpected '->' (T_OBJECT_OPERATOR)

Viewed 652

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

1 Answers

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

Related