Laravel 5 - Php artisan syntax error

☆樱花仙子☆ 提交于 2019-12-20 17:35:43

问题


I am currently developing an app with Laravel 5 and suddenly the artisan stoped working!

I can't use a single command on it, it always return the error:

      [Symfony\Component\Debug\Exception\FatalErrorException]
      syntax error, unexpected ',', expecting variable (T_VARIABLE)

I tried to update via composer but when the artisan tries to clear-complie

Command: composer update

> php artisan clear-compiled

  [Symfony\Component\Debug\Exception\FatalErrorException]
  syntax error, unexpected ',', expecting variable (T_VARIABLE)

Has anyone ever had this error before?

My Php version is 5.6.8


回答1:


I've found the error!

I had a syntax error on my routes.php file...

function($id,**name**,**value**)

Forgot the $ sign and thus it found a unexpected ','.

Thank you all for the help!




回答2:


Try this command:

php -S localhost:8000 -t public

Then execute it on browser, it will produce the error, just look at the error, and fix it.




回答3:


Instead of executing the commands using command prompt. It will be easy to look at LOG file found at location/directory

storage/logs/laravel.log

I am sure, you can easily check the log file and fix the syntax error.




回答4:


I recently ran into this same error, although the error was probably a different cause from yours. Turns out we had recently updated to PHP 7 and I hadn't upgraded yet. The issue was caused by a return type being set on a function, which wasn't supported in my local version of php. Ran an update on Homestead, which upgraded my PHP version and fixed the issue.




回答5:


Try running with the verbose argument, like so:

php artisan ... --verbose



回答6:


None of these solutions will always work.

php artisan tinker --verbose will often not give you the stack trace which will show the source of the error.

running in the browser will also not always give the error.

The solution is simple : look in storage/logs/laravel.log there the full stack trace will show

For ease of finding (if file is huge), open the file, delete all contents, run tinker and when come back only the specific error info will be there.

Hope this helps someone else




回答7:


I have received the same error in routes.php. I have given the wrong Route.

I put Route::get('/admin' , AdminController@index); instead of Route::get('/admin' , 'AdminController@index');

I forgot single quotes. Please check yours.



来源:https://stackoverflow.com/questions/32312693/laravel-5-php-artisan-syntax-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!