Photo by Surface on Unsplash

Now we can use dot prefix in Laravel 11

Dot Prefixes Are Here!

#[Pragmatic(Kiwi)]
3 min readMar 14, 2024

--

Before Laravel 11, utilizing dot prefixes like “database.dbo.” in your database schema design was impractical due to a bug related to parameter parsing via explode.

This bug, believed to have been present since 2017, caused unintended behavior when encountering dots.

You can see the threads here:

The problem might have had a big impact on people using MSSQL Databases. And the only workaround was to use an Expression.

Because using an Expression would bypass some wraps/processes it was a nice workaround for this.

But if it was a string, the code would arrive here, the prefix would get broken down at the explode method be separated into two values, and passed in the wrap segments…

Funnily enough, would pass the value back to wrap as it found multiple elements in the array (because MSSQL databases have prefixes like ‘database.dbo.’ ).

To better grasp what is happening, here is a schema of what it was happening

Gladly, this issue is fixed in Laravel 11 as more checks are in place for this.

More logic has been added to the wrapTable method that handles cases like this:

If you want to test it out fast, go to your config/database.php file, add a prefix to your database connection, and then head to console.php.

Here, let’s write a simple query and see if it gets translated to SQL:

routes/console.php

Artisan::command('mssql', function () {
$sql = DB::table("report")->toSql();

dd($sql);
});

This will indeed result in our correct MSSQL query:

The same thing we did here, would result in a segmentation fault if we did it in an earlier version.

--

--