Laravel 5 - Php 工匠语法错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32312693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:54:25  来源:igfitidea点击:

Laravel 5 - Php artisan syntax error

phplaravelcomposer-phpartisan

提问by gabahulk

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

我目前正在使用 Laravel 5 开发一个应用程序,突然工匠停止工作了!

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

我的 PHP 版本是 5.6.8

回答by gabahulk

I've found the error!

我发现了错误!

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

我的 routes.php 文件有语法错误...

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

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

忘记了 $ 符号,因此它发现了一个意外的 ','。

Thank you all for the help!

谢谢大家的帮助!

回答by Bill Tanthowi Jauhari

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.

然后在浏览器上执行,它会产生错误,只需查看错误,并修复它。

回答by Mahesh Yadav

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

而不是使用命令提示符执行命令。很容易查看在位置/目录中找到的 LOG 文件

storage/logs/laravel.log

存储/日志/laravel.log

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

我敢肯定,您可以轻松检查日志文件并修复语法错误。

回答by Tyler

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.

我最近遇到了同样的错误,尽管该错误可能与您的原因不同。原来我们最近更新到 PHP 7 而我还没有升级。该问题是由在函数上设置的返回类型引起的,我的本地版本的 php 不支持该返回类型。对 Homestead 进行了更新,它升级了我的 PHP 版本并修复了该问题。

回答by funerr

Try running with the verboseargument, like so:

尝试使用详细参数运行,如下所示:

php artisan ... --verbose

回答by yak

None of these solutions will always work.

这些解决方案都不会永远有效。

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

php artisan tinker --verbose通常不会为您提供显示错误来源的堆栈跟踪。

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

在浏览器中运行也不会总是出现错误。

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

解决方案很简单:查看storage/logs/laravel.log那里会显示完整的堆栈跟踪

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.

为了便于查找(如果文件很大),请打开文件,删除所有内容,运行 tinker,返回时只有特定的错误信息会在那里。

Hope this helps someone else

希望这对其他人有帮助

回答by Aditya Kompella

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

我在routes.php 中收到了同样的错误。我给出了错误的路线。

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

我把Route::get('/admin' , AdminController@index);而不是Route::get('/admin' , 'AdminController@index');

I forgot single quotes. Please check yours.

我忘了单引号。请检查你的。