2015-12-13 04:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2018-08-31 13:47:15 +00:00
|
|
|
use Illuminate\Database\DatabaseManager;
|
|
|
|
use Illuminate\Database\Schema\Builder;
|
2017-10-22 15:02:43 +00:00
|
|
|
use Illuminate\Database\SQLiteConnection;
|
2015-12-13 04:42:28 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2018-08-31 13:47:15 +00:00
|
|
|
use Illuminate\Validation\Factory as Validator;
|
2020-12-22 20:11:22 +00:00
|
|
|
use Laravel\Tinker\TinkerServiceProvider;
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bootstrap any application services.
|
|
|
|
*/
|
2018-08-31 13:47:15 +00:00
|
|
|
public function boot(Builder $schema, DatabaseManager $db, Validator $validator): void
|
2015-12-13 04:42:28 +00:00
|
|
|
{
|
2017-04-19 04:22:02 +00:00
|
|
|
// Fix utf8mb4-related error starting from Laravel 5.4
|
2018-08-31 13:47:15 +00:00
|
|
|
$schema->defaultStringLength(191);
|
2017-04-19 04:22:02 +00:00
|
|
|
|
2017-10-22 15:02:43 +00:00
|
|
|
// Enable on delete cascade for sqlite connections
|
2018-08-31 13:47:15 +00:00
|
|
|
if ($db->connection() instanceof SQLiteConnection) {
|
|
|
|
$db->statement($db->raw('PRAGMA foreign_keys = ON'));
|
2017-10-22 15:02:43 +00:00
|
|
|
}
|
|
|
|
|
2015-12-13 04:42:28 +00:00
|
|
|
// Add some custom validation rules
|
2018-08-31 13:47:15 +00:00
|
|
|
$validator->extend('path.valid', static function ($attribute, $value): bool {
|
2015-12-14 13:22:39 +00:00
|
|
|
return is_dir($value) && is_readable($value);
|
2015-12-13 04:42:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*/
|
2018-08-29 04:06:17 +00:00
|
|
|
public function register(): void
|
2015-12-13 04:42:28 +00:00
|
|
|
{
|
2019-06-30 14:22:53 +00:00
|
|
|
if ($this->app->environment() !== 'production') {
|
2020-12-22 20:11:22 +00:00
|
|
|
$this->app->register(TinkerServiceProvider::class);
|
2017-05-10 09:49:12 +00:00
|
|
|
}
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
}
|