douyou2368 2016-03-17 15:44
浏览 92

如何在Laravel中调试错误,如意外';'

I have started learning Laravel from last few days and during the course I keep getting errors like

unexpected ';'

below is the detailed error

FatalErrorException in 
home/ubuntu/workspace/storage/framework/views/d54ff8380f369dc8c9bc785ef2c17d66e0f399b3.php line 10: syntax error, 
unexpected ';'

Though I was able to find the cause of the error, which was again because of one typographical mistake in one of my view file i.e. create.blade.php .

My question is how to debug similar kind of error in large projects as error don't points out the exact file-name where syntax error was happening though the line number mentioned was the correct one ?

Please do let me know if I am not clear in my above question.

P.S. I checked the logs as well and it says the same thing.

Thanks in advance, Sambhav

  • 写回答

1条回答 默认 最新

  • dongquqiao2010 2016-03-17 15:58
    关注

    Well, this error is difficult to find when you are starting with laravel, or even worst, when you have kilometers in laravel but have a tons of view compiled at the same layout.

    Generally this errors comes when you put a semicolon in blade syntax like this:

    @if($something == true)
        // code here
    @endif;
    

    See the semicolon at endif? well, that breaks laravel's view. Another classic is:

    @lang('app.hello');
    

    or

    @endforeach;
    

    You need to review in that keywords if it has semicolon at the end. What I do sometimes is to call the views individually to isolate the error, it is easiest to find the error when you find the view in concrete. Why laravel does not display the current line number in the view where the errors is jumping? This is because laravel at first place compile blade syntax into html file, this file is cached to increase response's speed. So, laravel will compile even types like these exists;

    评论

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000