Skip to content

Instantly share code, notes, and snippets.

@jpswade
Created August 1, 2021 10:35

Revisions

  1. jpswade created this gist Aug 1, 2021.
    26 changes: 26 additions & 0 deletions SqliteTrait.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <?php

    namespace App\Traits;

    use Illuminate\Database\SQLiteConnection;
    use Illuminate\Support\Facades\DB;

    trait SqliteTrait
    {
    protected static function setUpSqlite(): void
    {
    $db = DB::connection();
    if ($db instanceof SQLiteConnection) {
    /** Fix: no such function: CONCAT */
    $db->getPdo()
    ->sqliteCreateFunction(
    'concat',
    function (...$input) {
    return implode('', $input);
    }
    );
    /** Fix: Cannot add a NOT NULL column with default value NULL */
    $db->getSchemaBuilder()->enableForeignKeyConstraints();
    }
    }
    }