简体   繁体   English

如何调试 Laravel 框架?

[英]How to debug Laravel framework?

I'm a newbie PHP programmer now casting an eye at frameworks, and among them Laravel sounds appealing to me as a beginner (somehow unfortunately because I've already invested in literature on Zend 2).我是一名新手 PHP 程序员,现在正在关注框架,其中 Laravel 听起来对我这个初学者很有吸引力(不幸的是,因为我已经投资了 Zend 2 的文献)。 However, debugging is important to me and from what I could find on the net, Laravel is hard to debug.然而,调试对我来说很重要,从我在网上可以找到的资料来看,Laravel 很难调试。 I currently use Xdebug in Netbeans on native PHP code and wonder whether Laravel can be debugged in the same or a similar way?我目前在 Netbeans 中对原生 PHP 代码使用 Xdebug,想知道 Laravel 是否可以以相同或类似的方式进行调试? When I open a new Netbeans project I can select Symfony 2 or Zend 2, but there seems to be indeed no support for other frameworks like Laravel?当我打开一个新的 Netbeans 项目时,我可以选择 Symfony 2 或 Zend 2,但似乎确实不支持 Laravel 等其他框架? If not, is there at least an equivalent debugging tool?如果没有,是否至少有一个等效的调试工具?

Laravel has its own debugging system.You can use built in dd() function.And there are several packages that can be used to debug laravel projects.Here are some links and hope that it will be helpful for you. Laravel 有自己的调试系统。你可以使用内置的 dd() 函数。并且有几个包可以用来调试 laravel 项目。这里有一些链接,希望对你有所帮助。

https://github.com/barryvdh/laravel-debugbar https://github.com/barryvdh/laravel-debugbar

http://laravel.io/forum/02-04-2014-package-laravel-debugbar http://laravel.io/forum/02-04-2014-package-laravel-debugbar

Recently I came to discover this amazing plugin that allows you to dump variables, trace requests, executions, views, controllers, queries, profile memory, execution time, etc., everything related to the current rendered page.最近我发现了这个神奇的插件,它允许你转储变量、跟踪请求、执行、视图、控制器、查询、配置文件内存、执行时间等,与当前渲染页面相关的所有内容。 Very helpful :非常有帮助 :

https://laravel-news.com/laravel-debugbar https://laravel-news.com/laravel-debugbar

You can install it via composer:您可以通过作曲家安装它:

composer require barryvdh/laravel-debugbar --dev

Then add it to your service providers array in /config/app.php然后将其添加到/config/app.php中的服务提供者数组中

The Debugbar will start working inmediately if the debug mode is turned on: To do it so, you just need to modify in your config/app.php or .env file the debug_mode to true .如果调试模式打开,调试栏将立即开始工作:为此,您只需在config/app.php.env文件中将debug_mode修改为true

If you wish to use the dump methods in the debugbar console, you need to include the alias to your /config/app.php array:如果您希望在调试栏控制台中使用转储方法,您需要在/config/app.php数组中包含别名:

'Debugbar' => Barryvdh\Debugbar\Facade::class,

Now you can start dumping variables like this:现在您可以像这样开始转储变量:

\Debugbar::info($variable);

Pretty cool plugin.很酷的插件。 Cheers!干杯!

laravel telescope laravel 望远镜

https://github.com/laravel/telescope https://github.com/laravel/telescope

in laracast you can find even a episodie about it在 laracast 你甚至可以找到关于它的剧集

https://laracasts.com/series/laravel-from-scratch-2018/episodes/28 https://laracasts.com/series/laravel-from-scratch-2018/episodes/28

还有 Laravel 的 Google Chrome 扩展“PHP 控制台”服务提供商https://github.com/barbushin/php-console-laravel

You can use the dephpugger.您可以使用 dephpugger。 Is a debugger to run in terminal.是在终端中运行的调试器。

Is really simple to use and works like byebug in ruby.使用起来非常简单,就像 ruby​​ 中的 byebug 一样工作。 https://github.com/tacnoman/dephpugger https://github.com/tacnoman/dephpugger

At first install this package:首先安装这个包:

composer require barryvdh/laravel-debugbar --dev

In config/app.php Add Inside providers array:在 config/app.php 里面添加 providers 数组:

Barryvdh\Debugbar\ServiceProvider::class,

And then aliases array:然后别名数组:

'Debugbar' => Barryvdh\Debugbar\Facade::class,

After that you can debugging by:之后,您可以通过以下方式进行调试:

Debugbar::info($object);
Debugbar::error('Error!');
Debugbar::warning('Watch out…');
Debugbar::addMessage('Another message', 'mylabel');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM