I’m in the process of adding Sentry to a Laravel app that uses Laravel Jetstream with Inertia.js and Vue 3, and the Sentry Vue 3 documentation wasn’t working for me because the app setup was wrapped inside a createInertiaApp function.
The key is to add Sentry in the setup method of that function:
Colin DeCarlo presented a talk at Laracon Online where among other useful tips, he demonstrated how to shim MySQL functions in an SQLite database (e.g., add functions that MySQL has but SQLite does not).
Here are two examples that I just needed in a project (FLOOR and DATEDIFF):
We’re using Laravel Socialite with a self-hosted GitLab instance to authenticate users for an internal tool.
Every time the session times out, the OAuth flow redirects the user back to the default dashboard, regardless of what URL the user originally requested.
However, Laravel provides a url.intended session key with the original URL; here’s how I used it, with a fallback to the dashboard URL:
I’ve recently been building an ecommerce app based on Laravel. Partway through development, we added geometry fields to a couple of tables in order to determine distances. I’ve been using this spatial package, so SQLite was not an option for my test suite.
As soon as I switched the testing database driver from SQLite to MariaDB, my tests immediately took an extra 12–13 seconds to run, regardless of whether I ran the entire test suite, a single file, or just one test.
This significantly lengthened the feedback loop when making changes to code and re-running tests.
So when I saw Jack Ellis mention that he uses MySQL for his test suite, it made me curious if he had the same issue.
He said that one of his test files runs 39 tests in < 2 seconds, so apparently it’s not been a problem for him.
Context
I’m using the LazilyRefreshDatabase trait added in Laravel 8.62.0 on my entire test suite
Many of my tables have constrained foreign keys referencing other tables
Comparisons
I decided to do some digging; here are comparisons using four different platforms for the same test in my application.
MariaDB
I’ve been using MariaDB as the main database platform on my development machine for years. Currently I’m on version 10.6.4.
In-Memory SQLite Database
I temporarily disabled the geometry features and tried the in-memory SQLite database (DB_CONNECTION=:memory:); it performed much better for the same tests:
A single test too <1s to run
An entire file with 16 tests took ~7s to run
SQLite File Database
I then tried with an SQLite file (DB_CONNECTION=sqlite), and it performed about the same:
A single test took ~1s to run
An entire file with 16 tests took ~7s to run
MySQL 8
I have an installation of MySQL 8 set up for one app that uses some specific MySQL 8 and I figured why not give that a try too.
Here are the results:
A single test took ~1.5s to run
An entire file with 16 tests took ~6.5s to run
Summary
For some reason, MariaDB takes approximately 12–13 seconds to tear down and recreate the database before starting to run tests, but MySQL is much faster.
While testing MariaDB, I opened the raw data directory for the database, and noticed chunks of files being removed and recreated at a time, so perhaps the foreign key constraints are (part of) the culprit here.
I do have 77 databases with ~3800 tables in my MariaDB installation built up from various projects over the years. It seems unlikely, but theoretically possible, that the server size could be part of the problem too.
I think I’ll experiment with switching back to MySQL as my development platform of choice.
Have you run into this same issue? Have any tips or tricks? Let me know in the comments.
I build an oEmbed provider in a Laravel application the other day and needed to parse an arbitrary URL to determine the route and parameters passed in order to determine the response.
Since I already had the routes built for the possible URLs, I didn’t want to duplicate code and re-parse them.
Here’s how I ended up retrieving the route and parameters:
I often use Xdebug for troubleshooting and interactively debugging local code as I write it.
Laravel’s artisan command is extremely useful for running code interactively during development. (It’s based on another utility named psysh.)
It can be very useful to set some debug breakpoints and then run code interactively using artisan, but occasionally when I run php artisan tinker, the PHP shell just sits there and doesn’t accept any input until I kill my xdebug listener.
However, I frequently forgot to run php artisan horizon when opening the project, and sometimes spent a bit of time trying to figure out why a job hadn’t run before remembering. 🤦
In addition—and this is a relatively minor annoyance—even when I do remember to start Horizon, sometimes I’d like to see the metrics dashboard showing how many jobs have run in the past few minutes.
Enter VS Code’s Tasks feature. This can automatically start running tasks when a workspace is opened.
To get set up:
If you haven’t yet, go to File > Save Workspace As… and save a workspace config file to somewhere on your hard drive
Open the command palette (command-shift-P) and activate “Tasks: Manage Automatic Tasks in Folder”
Activate “Allow Automatic Tasks”
Open the command palette again and activate “Workspaces: Open Workspace Configuration File”
Add the following to the workspace config file:
Now every time I open the workspace, assets are rebuilt as I modify them; Horizon, Pulse, and the scheduler start running automatically; and stale logs and failed jobs are pruned, keeping my database at a manageable size.