@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | /* |
8 | 8 | * Create an index if it doesn't exist yet |
9 | 9 | */ |
10 | -Blueprint::macro('createIndexIfNotExists', function ($columns, $name = null, $connection = null) { |
|
10 | +Blueprint::macro('createIndexIfNotExists', function($columns, $name = null, $connection = null) { |
|
11 | 11 | return $this->hasIndex($columns, $connection) |
12 | 12 | ? $this |
13 | 13 | : $this->index($columns, $name ?: $this->createIndexNameByColumns($columns)); |
@@ -16,21 +16,21 @@ discard block |
||
16 | 16 | /* |
17 | 17 | * Check if an index exists |
18 | 18 | */ |
19 | -Blueprint::macro('hasIndex', function ($columns) { |
|
19 | +Blueprint::macro('hasIndex', function($columns) { |
|
20 | 20 | return $this->getIndexNameByColumns($columns) !== null; |
21 | 21 | }); |
22 | 22 | |
23 | 23 | /* |
24 | 24 | * Get an index name by columns |
25 | 25 | */ |
26 | -Blueprint::macro('getIndexNameByColumns', function ($columns) { |
|
26 | +Blueprint::macro('getIndexNameByColumns', function($columns) { |
|
27 | 27 | if (is_string($columns)) { |
28 | 28 | $columns = [$columns]; |
29 | 29 | } |
30 | 30 | |
31 | 31 | $schemaManager = Schema::getConnection()->getDoctrineSchemaManager(); |
32 | 32 | $indices = $schemaManager->listTableIndexes($this->getTable()); |
33 | - $filteredIndices = collect($indices)->filter(function (Index $index) use ($columns) { |
|
33 | + $filteredIndices = collect($indices)->filter(function(Index $index) use ($columns) { |
|
34 | 34 | return compare_array($index->getColumns(), $columns); |
35 | 35 | }); |
36 | 36 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | /* |
45 | 45 | * Create an index name based on columns |
46 | 46 | */ |
47 | -Blueprint::macro('createIndexNameByColumns', function ($columns) { |
|
47 | +Blueprint::macro('createIndexNameByColumns', function($columns) { |
|
48 | 48 | if (is_string($columns)) { |
49 | 49 | $columns = [$columns]; |
50 | 50 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | /* |
62 | 62 | * Drop an index if it exists |
63 | 63 | */ |
64 | -Blueprint::macro('dropIndexIfExists', function ($columns) { |
|
64 | +Blueprint::macro('dropIndexIfExists', function($columns) { |
|
65 | 65 | if ($this->hasIndex($columns)) { |
66 | 66 | return $this->dropIndex($this->getIndexNameByColumns($columns)); |
67 | 67 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | return $this; |
70 | 70 | }); |
71 | 71 | |
72 | -if (! function_exists('compare_array')) { |
|
72 | +if ( ! function_exists('compare_array')) { |
|
73 | 73 | function compare_array($arrayA, $arrayB): bool |
74 | 74 | { |
75 | 75 | return |
@@ -6,9 +6,9 @@ discard block |
||
6 | 6 | /* |
7 | 7 | * Foreign Key |
8 | 8 | */ |
9 | -Blueprint::macro('addForeign', function ($table, $options = []) { |
|
9 | +Blueprint::macro('addForeign', function($table, $options = []) { |
|
10 | 10 | $fk = (isset($options['fk']) && ! empty($options['fk'])) ? |
11 | - $options['fk'] : strtolower(Str::singular($table)).'_id'; |
|
11 | + $options['fk'] : strtolower(Str::singular($table)) . '_id'; |
|
12 | 12 | |
13 | 13 | $reference = (isset($options['reference']) && ! empty($options['reference'])) ? |
14 | 14 | $options['reference'] : 'id'; |
@@ -23,34 +23,34 @@ discard block |
||
23 | 23 | $schema->nullable(); |
24 | 24 | } |
25 | 25 | |
26 | - if (! isset($options['no_reference'])) { |
|
26 | + if ( ! isset($options['no_reference'])) { |
|
27 | 27 | $this->referenceOn($fk, $table, $reference); |
28 | 28 | } |
29 | 29 | |
30 | 30 | return $schema; |
31 | 31 | }); |
32 | 32 | |
33 | -Blueprint::macro('addNullableForeign', function ($table, $fk, $bigInteger = false) { |
|
34 | - return $this->addForeign($table, ['nullable' => true, 'fk' => $fk, 'bigInteger' => $bigInteger])->comment('Nullable FK for '.$table); |
|
33 | +Blueprint::macro('addNullableForeign', function($table, $fk, $bigInteger = false) { |
|
34 | + return $this->addForeign($table, ['nullable' => true, 'fk' => $fk, 'bigInteger' => $bigInteger])->comment('Nullable FK for ' . $table); |
|
35 | 35 | }); |
36 | 36 | |
37 | -Blueprint::macro('referenceOn', function ($key, $table, $reference = 'id') { |
|
37 | +Blueprint::macro('referenceOn', function($key, $table, $reference = 'id') { |
|
38 | 38 | return $this->foreign($key) |
39 | 39 | ->references($reference) |
40 | 40 | ->on($table); |
41 | 41 | }); |
42 | 42 | |
43 | -Blueprint::macro('belongsTo', function ($table, $key = null, $bigInteger = false, $reference = 'id') { |
|
43 | +Blueprint::macro('belongsTo', function($table, $key = null, $bigInteger = false, $reference = 'id') { |
|
44 | 44 | if (is_null($key)) { |
45 | - $key = strtolower(Str::singular($table)).'_id'; |
|
45 | + $key = strtolower(Str::singular($table)) . '_id'; |
|
46 | 46 | } |
47 | 47 | |
48 | - return $this->addForeign($table, ['fk' => $key, 'reference' => $reference, 'bigInteger' => $bigInteger])->comment('FK for '.$table); |
|
48 | + return $this->addForeign($table, ['fk' => $key, 'reference' => $reference, 'bigInteger' => $bigInteger])->comment('FK for ' . $table); |
|
49 | 49 | }); |
50 | 50 | |
51 | -Blueprint::macro('nullableBelongsTo', function ($table, $key = null, $bigInteger = false, $reference = 'id') { |
|
51 | +Blueprint::macro('nullableBelongsTo', function($table, $key = null, $bigInteger = false, $reference = 'id') { |
|
52 | 52 | if (is_null($key)) { |
53 | - $key = strtolower(Str::singular($table)).'_id'; |
|
53 | + $key = strtolower(Str::singular($table)) . '_id'; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $this->addNullableForeign($table, $key, $bigInteger); |
@@ -5,30 +5,30 @@ |
||
5 | 5 | /* |
6 | 6 | * Acceptance |
7 | 7 | */ |
8 | -Blueprint::macro('addAcceptance', function ($value, $table_by = 'users', $is_default = true) { |
|
8 | +Blueprint::macro('addAcceptance', function($value, $table_by = 'users', $is_default = true) { |
|
9 | 9 | $this->is($value, $is_default); |
10 | 10 | $this->at($value); |
11 | 11 | $this->by($table_by, $value); |
12 | - $this->remarks($value.'_remarks'); |
|
12 | + $this->remarks($value . '_remarks'); |
|
13 | 13 | |
14 | 14 | return $this; |
15 | 15 | }); |
16 | 16 | |
17 | -Blueprint::macro('status', function ($key = 'status', $default = true) { |
|
17 | +Blueprint::macro('status', function($key = 'status', $default = true) { |
|
18 | 18 | return $this->boolean($key)->default($default)->comment('Status'); |
19 | 19 | }); |
20 | 20 | |
21 | -Blueprint::macro('is', function ($key = 'activated', $default = true, $prefix = 'is_') { |
|
22 | - return $this->status($prefix.$key, $default)->comment('Is it '.$key.'?'); |
|
21 | +Blueprint::macro('is', function($key = 'activated', $default = true, $prefix = 'is_') { |
|
22 | + return $this->status($prefix . $key, $default)->comment('Is it ' . $key . '?'); |
|
23 | 23 | }); |
24 | 24 | |
25 | -Blueprint::macro('at', function ($key = 'activated', $suffix = '_at') { |
|
26 | - return $this->datetime($key.$suffix)->nullable()->comment('Event occured at Date & Time'); |
|
25 | +Blueprint::macro('at', function($key = 'activated', $suffix = '_at') { |
|
26 | + return $this->datetime($key . $suffix)->nullable()->comment('Event occured at Date & Time'); |
|
27 | 27 | }); |
28 | 28 | |
29 | -Blueprint::macro('by', function ($table, $key = null, $nullable = true, $bigInteger = false, $suffix = '_by') { |
|
29 | +Blueprint::macro('by', function($table, $key = null, $nullable = true, $bigInteger = false, $suffix = '_by') { |
|
30 | 30 | return $this->addForeign($table, [ |
31 | - 'fk' => (! is_null($key) ? $key.$suffix : null), |
|
31 | + 'fk' => ( ! is_null($key) ? $key . $suffix : null), |
|
32 | 32 | 'nullable' => $nullable, |
33 | 33 | 'bigInteger' => $bigInteger, |
34 | 34 | ]); |
@@ -11,18 +11,18 @@ |
||
11 | 11 | */ |
12 | 12 | public function boot() |
13 | 13 | { |
14 | - collect(glob(__DIR__.'/Database/Schema/macros/*.php')) |
|
15 | - ->each(function ($path) { |
|
14 | + collect(glob(__DIR__ . '/Database/Schema/macros/*.php')) |
|
15 | + ->each(function($path) { |
|
16 | 16 | require $path; |
17 | 17 | }); |
18 | 18 | |
19 | 19 | /* A little hack to have Builder::hasMacro */ |
20 | - \Illuminate\Database\Eloquent\Builder::macro('hasMacro', function ($name) { |
|
20 | + \Illuminate\Database\Eloquent\Builder::macro('hasMacro', function($name) { |
|
21 | 21 | return isset(static::$macros[$name]); |
22 | 22 | }); |
23 | 23 | |
24 | - collect(glob(__DIR__.'/Models/macros/*.php')) |
|
25 | - ->each(function ($path) { |
|
24 | + collect(glob(__DIR__ . '/Models/macros/*.php')) |
|
25 | + ->each(function($path) { |
|
26 | 26 | require $path; |
27 | 27 | }); |
28 | 28 | } |