Last active
October 7, 2024 12:05
-
-
Save cloudwales/b4bd4b9da54d2d2ffe945ea446661dbc to your computer and use it in GitHub Desktop.
Laravel DigitalOcean Migration DB fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Illuminate\Database\Eloquent\Model; | |
use Illuminate\Database\Events\MigrationsEnded; | |
use Illuminate\Database\Events\MigrationsStarted; | |
use Illuminate\Support\Facades\DB; | |
use Illuminate\Support\Facades\Event; | |
use Illuminate\Support\Facades\URL; | |
use Illuminate\Support\ServiceProvider; | |
class AppServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register any application services. | |
*/ | |
public function register(): void | |
{ | |
// check this one here https://github.com/laravel/framework/issues/33238#issuecomment-897063577 | |
Event::listen(MigrationsStarted::class, function (){ | |
if (config('databases.allow_disabled_pk')) { | |
DB::statement('SET SESSION sql_require_primary_key=0'); | |
} | |
}); | |
Event::listen(MigrationsEnded::class, function (){ | |
if (config('databases.allow_disabled_pk')) { | |
DB::statement('SET SESSION sql_require_primary_key=1'); | |
} | |
}); | |
} | |
/** | |
* Bootstrap any application services. | |
*/ | |
public function boot(): void | |
{ | |
// Model::unguard(); | |
if (env('APP_ENV') == 'production' || env('APP_ENV') == 'beta') { | |
URL::forceScheme('https'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment