This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

JonasJonny
JonasJonny

Hello guys. Thanks for a great work on October. I really like your CMS.

The question is how can I debug variables, db queries etc.?

What is the best practice to debug in October/Laravel?

I found TWIG dump and enabled it through https://github.com/octobercms/october/issues/278#issuecomment-47453739. It's working fine but I am looking for a better options - more details.

Something like "laravel-debugbar" https://octobercms.com/forum/post/explain-please-right-using-of-composer.

It would be great have a tutorial or something about debugging. It's almost the most important thing for newcomers.

Thank you

Last updated

benfreke
benfreke

xdebug. It's a pain to set up sometimes, but it's definitely the best way.

I've got it working with a Laravel install using Vagrant and PHPStorm, and it's fantastic for stepping through lines of code. Once I've got it working with October on a different machine I'll post some information. I appear to have missed a step with that Vagrant box so it's not ready yet.

adis.osmonov
adis.osmonov

barryvdh/laravel-debugbar is fantastic tool

  1. Add "barryvdh/laravel-debugbar": "1.*" to your composer.json in root folder. Note: If this file is missing in your project you should copy that from october repo and some other missing files like .gitignore and others
  2. Do composer update
  3. After updating composer, add the ServiceProvider to the providers array in app/config/app.php 'Barryvdh\Debugbar\ServiceProvider',
  4. You need to publish the assets from this package php artisan debugbar:publish
  5. Add the following entry into the return array for getFunctions()
    new Twig_SimpleFunction('dump', ['\Barryvdh\Debugbar\Facade', 'info'], ['is_safe' => ['html']]),

    in modules/cms/twig/Extension.php

  6. Paste in your twig template {{ dump(your_variable) }} Imgur
  7. Refresh page Imgur

Note: After updating octobercms core you should repeat step 5

Last updated

daftspunky
daftspunky

Someone should convert this to a plugin perhaps?

JonasJonny
JonasJonny

Thank you guys.

BTW: Maybe "laravel-debugbar" should be in October by default.

adis.osmonov
adis.osmonov

I think it's better convert it to plugin as daftspunk suggested, because after october:update it doesn't locate debugbar's provider, so I need to do composer update

emzero439
emzero439

I followed the steps above to add the debugbar but it failed when running php artisan debugbar:publish

PHP Fatal error:  Class 'Barryvdh\Debugbar\ServiceProvider' not found in /vagrant/mbtassino/vendor/laravel/framework/src
/Illuminate/Foundation/ProviderRepository.php on line 158
PHP Stack trace:
PHP   1. {main}() /vagrant/mbtassino/artisan:0
PHP   2. require_once() /vagrant/mbtassino/artisan:30
PHP   3. require() /vagrant/mbtassino/bootstrap/start.php:57
PHP   4. Illuminate\Foundation\ProviderRepository->load() /vagrant/mbtassino/vendor/laravel/framework/src/Illuminate/Fou
ndation/start.php:210
PHP   5. Illuminate\Foundation\ProviderRepository->compileManifest() /vagrant/mbtassino/vendor/laravel/framework/src/Ill
uminate/Foundation/ProviderRepository.php:58
PHP   6. Illuminate\Foundation\ProviderRepository->createProvider() /vagrant/mbtassino/vendor/laravel/framework/src/Illu
minate/Foundation/ProviderRepository.php:122
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Class 'Barryvdh\\Debugbar\\Servi
ceProvider' not found","file":"\/vagrant\/mbtassino\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/ProviderRe
pository.php","line":158}}

Last updated

adis.osmonov
adis.osmonov

Another way. Put it on app/start/global.php or bootstrap/start.php

\System\Classes\MarkupManager::instance()->registerCallback(function($manager){
    $manager->registerFunctions([
        'dump' => function($param){
            return \Debugbar::info($param);
        },
    ]);
});

Put in on twig file:

{{ dump('test') }}
adis.osmonov
adis.osmonov

@emzero439 do composer update after php artisan october:update

Related https://github.com/octobercms/october/issues/456

NOTE: in my case I need to do rm -r vendor/composer before composer update

Last updated

barryvdh2622
barryvdh2622

Hey guys, I added some extensions for laravel-debugbar to my projects, to replace the dump function and add a stopwatch tag. It's in dev-master for now, is that helpful for you? See https://github.com/barryvdh/laravel-debugbar/blob/master/readme.md#twig-integration

Let me know if I can do something to help. (Not a October user myself)

Flynsarmy
Flynsarmy

I've written a DebugBar plugin to integrate Laravel Debugbar. Check it out on GitHub.

Last updated

barryvdh2622
barryvdh2622

Cool. You could consider registering the 2 Twig extensions in your Plugin also, if you want access to the dump function and stopwatch tag.

Flynsarmy
Flynsarmy

Thanks for the tip, @barryvdh2622. I'll add them tomorrow. One other thing, can you somehow allow your debugbar:publish command to take a path argument? October doesn't support a top level packages directory. I'd also then need a config option for the asset directory (defaulting to what you have at the moment) so that the URLs output in HTML source by your plugin point to the correct location.

I'd like to be able to publish to an assets directory in my plugin or some other public directory automatically on plugin installation. At the moment as you can see from this monstrosity I'm just str_replaceing the path you output to HTML source with your packages original asset locations. It's very ugly and prone to errors if you change things around in future.

Last updated

barryvdh2622
barryvdh2622

Hmm, I noticed. I also saw that Middleware doesn't work, so perhaps I could add a check for that too. Any idea's what would be the best way to detect that? Does October has some specific version/constant I can check?

Flynsarmy
Flynsarmy

@barryvdh2622 The twig extensions have been added and will be available and working as soon as my PR is merged.

As for an october-specific constant, I'm not sure. You'd have to ask SamuelGeorges/daftspunk in the #october IRC room or get very lucky and have him grace us with his presence on the forum here :)

Last updated

axomat
axomat

Hi Flynsarmy The debugbar works great thanks (and should be a proper published plugin when the PR comes through of course). The only part of it that I cant see any output for is the twig dump() command which does not error it just does nothing. The stopwatch command is working fine, as are the debugbar:: commands. Any suggestions?

Flynsarmy
Flynsarmy

Adding {{ dump(this) }} works fine on my layout. Not sure what your problem could be. Try hitting save again - I've noticed sometimes October will serve up a cached copy of the page until you resave your page/partial/layout.

Other than that the usual - check your error logs. I take it you implimented my patch manually? Because I didn't think the update had been released to the public yet.

EDIT: Also the reason the plugin isn't on the marketplace is because it requires in an entire Laravel distro bloating it up to a 12MB plugin. Sam understandably doesn't want that and I don't want to fork it and copy just the required folders in because that messes with my workflow.

Last updated

axomat
axomat

Yes I implemented manually and stopwatch works so I dont think that is the problem.

I have tried it in an October page through the backend and added it to a partial in a plugin. No luck in either.

Oh well I can live without it, I needed the Debugbar:: commands for debugging ajax stuff for which it is great.

Flynsarmy
Flynsarmy

@axomat OK, I can replicate. It appears to be a bug in October. October's twig is never set to debug mode. I've left a PR here which Sam has shown approval of but not yet merged.

Last updated

Flynsarmy
Flynsarmy

@barryvdh2622 Could you please remove the //# sourceMappingURL=jquery.min.map line from the bottom of your src/DebugBar/Resources/vendor/jquery/dist/jquery.min.js file? You don't include a map file in that same directory so it results in a 404 on every page load.

Last updated

1-20 of 22

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.