Use with laravel tinker?
Is it possible to log the queries when testing with laravel tinker? If so, can you provide instructions on how to enable it? I reviewed the docs and searched the issues, I don't see any other mention of using Tinker.
I don't think so, unless it works with collecting artisan commands? Have you tried turning it on?
I tried messing with the settings to see if that was the reason it wasn't working. I can confirm it doesn't log anything when using tinker with artisan commands enabled. I'd like to suggest it as a feature. Love the package anyway!
I had a similar need. I solved it with a custom Psy-Shell command:
use Psy\Command\ReflectingCommand;
use Psy\VarDumper\Presenter;
use Psy\VarDumper\PresenterAware;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class MonitorDb extends ReflectingCommand implements PresenterAware
{
private ?Presenter $presenter = null;
/**
* PresenterAware interface.
*
* @param Presenter $presenter
*/
public function setPresenter(Presenter $presenter): void
{
$this->presenter = $presenter;
}
/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
->setName('monitor_db')
->setAliases(['mdb', 'debug_db', 'ddb'])
->setDescription('Start monitoring database queries');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
\DB::listen(function ($query) use ($output){
$data = [
'sql' => $query->sql,
'bindings' => $query->bindings,
'execution_time' => $query->time,
];
$output->writeln($this->presenter->present($data));
});
return 0;
}
}
You need to load the command in your config.tinker.php (which you need to enable in you .env).
Would be useful to also have it working with Tinkerwell