To log SQLite queries in Laravel Telescope or Laravel Debugbar, you should ensure that your application is set up correctly to log queries regardless of the database driver being used. Here's how you can ensure that your SQLite queries are logged:
-
Enable Query Logging in Laravel: Laravel allows you to listen for query events, which you can use to log queries. You can place the following code in a service provider, such as
AppServiceProvider, within thebootmethod:use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; public function boot() { if (env('APP_DEBUG')) { DB::listen(function ($query) { Log::info($query->sql, $query->bindings, $query->time); }); } }This will log all queries to the default Laravel log file. However, Laravel Debugbar and Telescope should automatically pick up these queries without this step, as they hook into the same underlying mechanism that Laravel uses for query logging.
-
Configure Laravel Debugbar: If you're using Laravel Debugbar, make sure it's installed and enabled in your
config/debugbar.phpconfiguration file. You should have something like this:'enabled' => env('DEBUGBAR_ENABLED', true),Also, ensure that the
collectorsarray has thequeriesenabled:'collectors' => [ // ... 'queries' => true, // ... ], -
Configure Laravel Telescope: For Laravel Telescope, ensure that you have the
Watchers\QueryWatcherenabled in yourconfig/telescope.phpconfiguration file:'watchers' => [ // ... \Laravel\Telescope\Watchers\QueryWatcher::class => [ 'enabled' => env('TELESCOPE_QUERY_WATCHER', true), 'ignore_packages' => true, 'slow' => 100, ], // ... ], -
Check Your Environment: Both Laravel Debugbar and Telescope are typically used in local development environments. Make sure that your
.envfile has theAPP_DEBUGvariable set totrue:APP_DEBUG=true -
Clear Configuration Cache: If you've made changes to your configuration files, make sure to clear the configuration cache with the following command:
php artisan config:clear -
Check Database Configuration: Finally, ensure that your SQLite database connection is configured correctly in your
config/database.phpfile. It should look something like this:'connections' => [ // ... 'sqlite' => [ 'driver' => 'sqlite', 'url' => env('DATABASE_URL'), 'database' => env('DB_DATABASE', database_path('database.sqlite')), 'prefix' => '', 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), ], // ... ],
If after following these steps, you still do not see SQLite queries in Laravel Debugbar or Telescope, there might be an issue specific to your application setup or a bug in the package. In such cases, it's a good idea to check the GitHub issues for the respective packages or seek further assistance from the community.