koel/app/Providers/AppServiceProvider.php
Fiete Börner 56799c5ffa enable foreign keys for sqlite connections (#672)
* enable foreign keys for sqlite connections

this code block enables the on delete cascade functionality for sqlite
connections

* fix code styling issues

* import the sqlite connnection class for consistency
2017-10-22 16:02:43 +01:00

46 lines
1.2 KiB
PHP

<?php
namespace App\Providers;
use DB;
use Illuminate\Database\SQLiteConnection;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// Fix utf8mb4-related error starting from Laravel 5.4
Schema::defaultStringLength(191);
// Enable on delete cascade for sqlite connections
if (DB::connection() instanceof SQLiteConnection) {
DB::statement(DB::raw('PRAGMA foreign_keys = ON'));
}
// Add some custom validation rules
Validator::extend('path.valid', function ($attribute, $value, $parameters, $validator) {
return is_dir($value) && is_readable($value);
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
if (!$this->app->environment('production')) {
$this->app->register('Laravel\Tinker\TinkerServiceProvider');
$this->app->register('Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider');
}
}
}