|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider; |
|
6
|
|
|
use Illuminate\Database\DatabaseManager; |
|
7
|
|
|
use Illuminate\Database\Schema\Builder; |
|
8
|
|
|
use Illuminate\Database\SQLiteConnection; |
|
9
|
|
|
use Illuminate\Support\ServiceProvider; |
|
10
|
|
|
use Illuminate\Validation\Factory as Validator; |
|
11
|
|
|
use Laravel\Tinker\TinkerServiceProvider; |
|
12
|
|
|
use Mpociot\ApiDoc\ApiDocGeneratorServiceProvider; |
|
13
|
|
|
|
|
14
|
|
|
class AppServiceProvider extends ServiceProvider |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Bootstrap any application services. |
|
18
|
|
|
*/ |
|
19
|
132 |
|
public function boot(Builder $schema, DatabaseManager $db, Validator $validator): void |
|
20
|
|
|
{ |
|
21
|
|
|
// Fix utf8mb4-related error starting from Laravel 5.4 |
|
22
|
132 |
|
$schema->defaultStringLength(191); |
|
23
|
|
|
|
|
24
|
|
|
// Enable on delete cascade for sqlite connections |
|
25
|
132 |
|
if ($db->connection() instanceof SQLiteConnection) { |
|
26
|
132 |
|
$db->statement($db->raw('PRAGMA foreign_keys = ON')); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
// Add some custom validation rules |
|
30
|
|
|
$validator->extend('path.valid', static function ($attribute, $value): bool { |
|
31
|
1 |
|
return is_dir($value) && is_readable($value); |
|
32
|
132 |
|
}); |
|
33
|
132 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Register any application services. |
|
37
|
|
|
*/ |
|
38
|
132 |
|
public function register(): void |
|
39
|
|
|
{ |
|
40
|
132 |
|
if ($this->app->environment() !== 'production') { |
|
41
|
132 |
|
$this->app->register(TinkerServiceProvider::class); |
|
42
|
132 |
|
$this->app->register(IdeHelperServiceProvider::class); |
|
43
|
132 |
|
$this->app->register(ApiDocGeneratorServiceProvider::class); |
|
44
|
|
|
} |
|
45
|
132 |
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|