Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Database\Schema;
4
 
5
use BadMethodCallException;
6
use Closure;
7
use Illuminate\Database\Connection;
8
use Illuminate\Database\Query\Expression;
9
use Illuminate\Database\Schema\Grammars\Grammar;
10
use Illuminate\Database\SQLiteConnection;
11
use Illuminate\Support\Fluent;
12
use Illuminate\Support\Traits\Macroable;
13
 
14
class Blueprint
15
{
16
    use Macroable;
17
 
18
    /**
19
     * The table the blueprint describes.
20
     *
21
     * @var string
22
     */
23
    protected $table;
24
 
25
    /**
26
     * The prefix of the table.
27
     *
28
     * @var string
29
     */
30
    protected $prefix;
31
 
32
    /**
33
     * The columns that should be added to the table.
34
     *
35
     * @var \Illuminate\Database\Schema\ColumnDefinition[]
36
     */
37
    protected $columns = [];
38
 
39
    /**
40
     * The commands that should be run for the table.
41
     *
42
     * @var \Illuminate\Support\Fluent[]
43
     */
44
    protected $commands = [];
45
 
46
    /**
47
     * The storage engine that should be used for the table.
48
     *
49
     * @var string
50
     */
51
    public $engine;
52
 
53
    /**
54
     * The default character set that should be used for the table.
55
     *
56
     * @var string
57
     */
58
    public $charset;
59
 
60
    /**
61
     * The collation that should be used for the table.
62
     *
63
     * @var string
64
     */
65
    public $collation;
66
 
67
    /**
68
     * Whether to make the table temporary.
69
     *
70
     * @var bool
71
     */
72
    public $temporary = false;
73
 
74
    /**
75
     * The column to add new columns after.
76
     *
77
     * @var string
78
     */
79
    public $after;
80
 
81
    /**
82
     * Create a new schema blueprint.
83
     *
84
     * @param  string  $table
85
     * @param  \Closure|null  $callback
86
     * @param  string  $prefix
87
     * @return void
88
     */
89
    public function __construct($table, Closure $callback = null, $prefix = '')
90
    {
91
        $this->table = $table;
92
        $this->prefix = $prefix;
93
 
94
        if (! is_null($callback)) {
95
            $callback($this);
96
        }
97
    }
98
 
99
    /**
100
     * Execute the blueprint against the database.
101
     *
102
     * @param  \Illuminate\Database\Connection  $connection
103
     * @param  \Illuminate\Database\Schema\Grammars\Grammar  $grammar
104
     * @return void
105
     */
106
    public function build(Connection $connection, Grammar $grammar)
107
    {
108
        foreach ($this->toSql($connection, $grammar) as $statement) {
109
            $connection->statement($statement);
110
        }
111
    }
112
 
113
    /**
114
     * Get the raw SQL statements for the blueprint.
115
     *
116
     * @param  \Illuminate\Database\Connection  $connection
117
     * @param  \Illuminate\Database\Schema\Grammars\Grammar  $grammar
118
     * @return array
119
     */
120
    public function toSql(Connection $connection, Grammar $grammar)
121
    {
122
        $this->addImpliedCommands($grammar);
123
 
124
        $statements = [];
125
 
126
        // Each type of command has a corresponding compiler function on the schema
127
        // grammar which is used to build the necessary SQL statements to build
128
        // the blueprint element, so we'll just call that compilers function.
129
        $this->ensureCommandsAreValid($connection);
130
 
131
        foreach ($this->commands as $command) {
132
            $method = 'compile'.ucfirst($command->name);
133
 
134
            if (method_exists($grammar, $method) || $grammar::hasMacro($method)) {
135
                if (! is_null($sql = $grammar->$method($this, $command, $connection))) {
136
                    $statements = array_merge($statements, (array) $sql);
137
                }
138
            }
139
        }
140
 
141
        return $statements;
142
    }
143
 
144
    /**
145
     * Ensure the commands on the blueprint are valid for the connection type.
146
     *
147
     * @param  \Illuminate\Database\Connection  $connection
148
     * @return void
149
     *
150
     * @throws \BadMethodCallException
151
     */
152
    protected function ensureCommandsAreValid(Connection $connection)
153
    {
154
        if ($connection instanceof SQLiteConnection) {
155
            if ($this->commandsNamed(['dropColumn', 'renameColumn'])->count() > 1
156
                && ! $connection->usingNativeSchemaOperations()) {
157
                throw new BadMethodCallException(
158
                    "SQLite doesn't support multiple calls to dropColumn / renameColumn in a single modification."
159
                );
160
            }
161
 
162
            if ($this->commandsNamed(['dropForeign'])->count() > 0) {
163
                throw new BadMethodCallException(
164
                    "SQLite doesn't support dropping foreign keys (you would need to re-create the table)."
165
                );
166
            }
167
        }
168
    }
169
 
170
    /**
171
     * Get all of the commands matching the given names.
172
     *
173
     * @param  array  $names
174
     * @return \Illuminate\Support\Collection
175
     */
176
    protected function commandsNamed(array $names)
177
    {
178
        return collect($this->commands)->filter(function ($command) use ($names) {
179
            return in_array($command->name, $names);
180
        });
181
    }
182
 
183
    /**
184
     * Add the commands that are implied by the blueprint's state.
185
     *
186
     * @param  \Illuminate\Database\Schema\Grammars\Grammar  $grammar
187
     * @return void
188
     */
189
    protected function addImpliedCommands(Grammar $grammar)
190
    {
191
        if (count($this->getAddedColumns()) > 0 && ! $this->creating()) {
192
            array_unshift($this->commands, $this->createCommand('add'));
193
        }
194
 
195
        if (count($this->getChangedColumns()) > 0 && ! $this->creating()) {
196
            array_unshift($this->commands, $this->createCommand('change'));
197
        }
198
 
199
        $this->addFluentIndexes();
200
 
201
        $this->addFluentCommands($grammar);
202
    }
203
 
204
    /**
205
     * Add the index commands fluently specified on columns.
206
     *
207
     * @return void
208
     */
209
    protected function addFluentIndexes()
210
    {
211
        foreach ($this->columns as $column) {
212
            foreach (['primary', 'unique', 'index', 'fulltext', 'fullText', 'spatialIndex'] as $index) {
213
                // If the index has been specified on the given column, but is simply equal
214
                // to "true" (boolean), no name has been specified for this index so the
215
                // index method can be called without a name and it will generate one.
216
                if ($column->{$index} === true) {
217
                    $this->{$index}($column->name);
218
                    $column->{$index} = false;
219
 
220
                    continue 2;
221
                }
222
 
223
                // If the index has been specified on the given column, and it has a string
224
                // value, we'll go ahead and call the index method and pass the name for
225
                // the index since the developer specified the explicit name for this.
226
                elseif (isset($column->{$index})) {
227
                    $this->{$index}($column->name, $column->{$index});
228
                    $column->{$index} = false;
229
 
230
                    continue 2;
231
                }
232
            }
233
        }
234
    }
235
 
236
    /**
237
     * Add the fluent commands specified on any columns.
238
     *
239
     * @param  \Illuminate\Database\Schema\Grammars\Grammar  $grammar
240
     * @return void
241
     */
242
    public function addFluentCommands(Grammar $grammar)
243
    {
244
        foreach ($this->columns as $column) {
245
            foreach ($grammar->getFluentCommands() as $commandName) {
246
                $attributeName = lcfirst($commandName);
247
 
248
                if (! isset($column->{$attributeName})) {
249
                    continue;
250
                }
251
 
252
                $value = $column->{$attributeName};
253
 
254
                $this->addCommand(
255
                    $commandName, compact('value', 'column')
256
                );
257
            }
258
        }
259
    }
260
 
261
    /**
262
     * Determine if the blueprint has a create command.
263
     *
264
     * @return bool
265
     */
266
    public function creating()
267
    {
268
        return collect($this->commands)->contains(function ($command) {
269
            return $command->name === 'create';
270
        });
271
    }
272
 
273
    /**
274
     * Indicate that the table needs to be created.
275
     *
276
     * @return \Illuminate\Support\Fluent
277
     */
278
    public function create()
279
    {
280
        return $this->addCommand('create');
281
    }
282
 
283
    /**
284
     * Indicate that the table needs to be temporary.
285
     *
286
     * @return void
287
     */
288
    public function temporary()
289
    {
290
        $this->temporary = true;
291
    }
292
 
293
    /**
294
     * Indicate that the table should be dropped.
295
     *
296
     * @return \Illuminate\Support\Fluent
297
     */
298
    public function drop()
299
    {
300
        return $this->addCommand('drop');
301
    }
302
 
303
    /**
304
     * Indicate that the table should be dropped if it exists.
305
     *
306
     * @return \Illuminate\Support\Fluent
307
     */
308
    public function dropIfExists()
309
    {
310
        return $this->addCommand('dropIfExists');
311
    }
312
 
313
    /**
314
     * Indicate that the given columns should be dropped.
315
     *
316
     * @param  array|mixed  $columns
317
     * @return \Illuminate\Support\Fluent
318
     */
319
    public function dropColumn($columns)
320
    {
321
        $columns = is_array($columns) ? $columns : func_get_args();
322
 
323
        return $this->addCommand('dropColumn', compact('columns'));
324
    }
325
 
326
    /**
327
     * Indicate that the given columns should be renamed.
328
     *
329
     * @param  string  $from
330
     * @param  string  $to
331
     * @return \Illuminate\Support\Fluent
332
     */
333
    public function renameColumn($from, $to)
334
    {
335
        return $this->addCommand('renameColumn', compact('from', 'to'));
336
    }
337
 
338
    /**
339
     * Indicate that the given primary key should be dropped.
340
     *
341
     * @param  string|array|null  $index
342
     * @return \Illuminate\Support\Fluent
343
     */
344
    public function dropPrimary($index = null)
345
    {
346
        return $this->dropIndexCommand('dropPrimary', 'primary', $index);
347
    }
348
 
349
    /**
350
     * Indicate that the given unique key should be dropped.
351
     *
352
     * @param  string|array  $index
353
     * @return \Illuminate\Support\Fluent
354
     */
355
    public function dropUnique($index)
356
    {
357
        return $this->dropIndexCommand('dropUnique', 'unique', $index);
358
    }
359
 
360
    /**
361
     * Indicate that the given index should be dropped.
362
     *
363
     * @param  string|array  $index
364
     * @return \Illuminate\Support\Fluent
365
     */
366
    public function dropIndex($index)
367
    {
368
        return $this->dropIndexCommand('dropIndex', 'index', $index);
369
    }
370
 
371
    /**
372
     * Indicate that the given fulltext index should be dropped.
373
     *
374
     * @param  string|array  $index
375
     * @return \Illuminate\Support\Fluent
376
     */
377
    public function dropFullText($index)
378
    {
379
        return $this->dropIndexCommand('dropFullText', 'fulltext', $index);
380
    }
381
 
382
    /**
383
     * Indicate that the given spatial index should be dropped.
384
     *
385
     * @param  string|array  $index
386
     * @return \Illuminate\Support\Fluent
387
     */
388
    public function dropSpatialIndex($index)
389
    {
390
        return $this->dropIndexCommand('dropSpatialIndex', 'spatialIndex', $index);
391
    }
392
 
393
    /**
394
     * Indicate that the given foreign key should be dropped.
395
     *
396
     * @param  string|array  $index
397
     * @return \Illuminate\Support\Fluent
398
     */
399
    public function dropForeign($index)
400
    {
401
        return $this->dropIndexCommand('dropForeign', 'foreign', $index);
402
    }
403
 
404
    /**
405
     * Indicate that the given column and foreign key should be dropped.
406
     *
407
     * @param  string  $column
408
     * @return \Illuminate\Support\Fluent
409
     */
410
    public function dropConstrainedForeignId($column)
411
    {
412
        $this->dropForeign([$column]);
413
 
414
        return $this->dropColumn($column);
415
    }
416
 
417
    /**
418
     * Indicate that the given foreign key should be dropped.
419
     *
420
     * @param  \Illuminate\Database\Eloquent\Model|string  $model
421
     * @param  string|null  $column
422
     * @return \Illuminate\Support\Fluent
423
     */
424
    public function dropForeignIdFor($model, $column = null)
425
    {
426
        if (is_string($model)) {
427
            $model = new $model;
428
        }
429
 
430
        return $this->dropForeign([$column ?: $model->getForeignKey()]);
431
    }
432
 
433
    /**
434
     * Indicate that the given foreign key should be dropped.
435
     *
436
     * @param  \Illuminate\Database\Eloquent\Model|string  $model
437
     * @param  string|null  $column
438
     * @return \Illuminate\Support\Fluent
439
     */
440
    public function dropConstrainedForeignIdFor($model, $column = null)
441
    {
442
        if (is_string($model)) {
443
            $model = new $model;
444
        }
445
 
446
        return $this->dropConstrainedForeignId($column ?: $model->getForeignKey());
447
    }
448
 
449
    /**
450
     * Indicate that the given indexes should be renamed.
451
     *
452
     * @param  string  $from
453
     * @param  string  $to
454
     * @return \Illuminate\Support\Fluent
455
     */
456
    public function renameIndex($from, $to)
457
    {
458
        return $this->addCommand('renameIndex', compact('from', 'to'));
459
    }
460
 
461
    /**
462
     * Indicate that the timestamp columns should be dropped.
463
     *
464
     * @return void
465
     */
466
    public function dropTimestamps()
467
    {
468
        $this->dropColumn('created_at', 'updated_at');
469
    }
470
 
471
    /**
472
     * Indicate that the timestamp columns should be dropped.
473
     *
474
     * @return void
475
     */
476
    public function dropTimestampsTz()
477
    {
478
        $this->dropTimestamps();
479
    }
480
 
481
    /**
482
     * Indicate that the soft delete column should be dropped.
483
     *
484
     * @param  string  $column
485
     * @return void
486
     */
487
    public function dropSoftDeletes($column = 'deleted_at')
488
    {
489
        $this->dropColumn($column);
490
    }
491
 
492
    /**
493
     * Indicate that the soft delete column should be dropped.
494
     *
495
     * @param  string  $column
496
     * @return void
497
     */
498
    public function dropSoftDeletesTz($column = 'deleted_at')
499
    {
500
        $this->dropSoftDeletes($column);
501
    }
502
 
503
    /**
504
     * Indicate that the remember token column should be dropped.
505
     *
506
     * @return void
507
     */
508
    public function dropRememberToken()
509
    {
510
        $this->dropColumn('remember_token');
511
    }
512
 
513
    /**
514
     * Indicate that the polymorphic columns should be dropped.
515
     *
516
     * @param  string  $name
517
     * @param  string|null  $indexName
518
     * @return void
519
     */
520
    public function dropMorphs($name, $indexName = null)
521
    {
522
        $this->dropIndex($indexName ?: $this->createIndexName('index', ["{$name}_type", "{$name}_id"]));
523
 
524
        $this->dropColumn("{$name}_type", "{$name}_id");
525
    }
526
 
527
    /**
528
     * Rename the table to a given name.
529
     *
530
     * @param  string  $to
531
     * @return \Illuminate\Support\Fluent
532
     */
533
    public function rename($to)
534
    {
535
        return $this->addCommand('rename', compact('to'));
536
    }
537
 
538
    /**
539
     * Specify the primary key(s) for the table.
540
     *
541
     * @param  string|array  $columns
542
     * @param  string|null  $name
543
     * @param  string|null  $algorithm
544
     * @return \Illuminate\Database\Schema\IndexDefinition
545
     */
546
    public function primary($columns, $name = null, $algorithm = null)
547
    {
548
        return $this->indexCommand('primary', $columns, $name, $algorithm);
549
    }
550
 
551
    /**
552
     * Specify a unique index for the table.
553
     *
554
     * @param  string|array  $columns
555
     * @param  string|null  $name
556
     * @param  string|null  $algorithm
557
     * @return \Illuminate\Database\Schema\IndexDefinition
558
     */
559
    public function unique($columns, $name = null, $algorithm = null)
560
    {
561
        return $this->indexCommand('unique', $columns, $name, $algorithm);
562
    }
563
 
564
    /**
565
     * Specify an index for the table.
566
     *
567
     * @param  string|array  $columns
568
     * @param  string|null  $name
569
     * @param  string|null  $algorithm
570
     * @return \Illuminate\Database\Schema\IndexDefinition
571
     */
572
    public function index($columns, $name = null, $algorithm = null)
573
    {
574
        return $this->indexCommand('index', $columns, $name, $algorithm);
575
    }
576
 
577
    /**
578
     * Specify an fulltext for the table.
579
     *
580
     * @param  string|array  $columns
581
     * @param  string|null  $name
582
     * @param  string|null  $algorithm
583
     * @return \Illuminate\Database\Schema\IndexDefinition
584
     */
585
    public function fullText($columns, $name = null, $algorithm = null)
586
    {
587
        return $this->indexCommand('fulltext', $columns, $name, $algorithm);
588
    }
589
 
590
    /**
591
     * Specify a spatial index for the table.
592
     *
593
     * @param  string|array  $columns
594
     * @param  string|null  $name
595
     * @return \Illuminate\Database\Schema\IndexDefinition
596
     */
597
    public function spatialIndex($columns, $name = null)
598
    {
599
        return $this->indexCommand('spatialIndex', $columns, $name);
600
    }
601
 
602
    /**
603
     * Specify a raw index for the table.
604
     *
605
     * @param  string  $expression
606
     * @param  string  $name
607
     * @return \Illuminate\Database\Schema\IndexDefinition
608
     */
609
    public function rawIndex($expression, $name)
610
    {
611
        return $this->index([new Expression($expression)], $name);
612
    }
613
 
614
    /**
615
     * Specify a foreign key for the table.
616
     *
617
     * @param  string|array  $columns
618
     * @param  string|null  $name
619
     * @return \Illuminate\Database\Schema\ForeignKeyDefinition
620
     */
621
    public function foreign($columns, $name = null)
622
    {
623
        $command = new ForeignKeyDefinition(
624
            $this->indexCommand('foreign', $columns, $name)->getAttributes()
625
        );
626
 
627
        $this->commands[count($this->commands) - 1] = $command;
628
 
629
        return $command;
630
    }
631
 
632
    /**
633
     * Create a new auto-incrementing big integer (8-byte) column on the table.
634
     *
635
     * @param  string  $column
636
     * @return \Illuminate\Database\Schema\ColumnDefinition
637
     */
638
    public function id($column = 'id')
639
    {
640
        return $this->bigIncrements($column);
641
    }
642
 
643
    /**
644
     * Create a new auto-incrementing integer (4-byte) column on the table.
645
     *
646
     * @param  string  $column
647
     * @return \Illuminate\Database\Schema\ColumnDefinition
648
     */
649
    public function increments($column)
650
    {
651
        return $this->unsignedInteger($column, true);
652
    }
653
 
654
    /**
655
     * Create a new auto-incrementing integer (4-byte) column on the table.
656
     *
657
     * @param  string  $column
658
     * @return \Illuminate\Database\Schema\ColumnDefinition
659
     */
660
    public function integerIncrements($column)
661
    {
662
        return $this->unsignedInteger($column, true);
663
    }
664
 
665
    /**
666
     * Create a new auto-incrementing tiny integer (1-byte) column on the table.
667
     *
668
     * @param  string  $column
669
     * @return \Illuminate\Database\Schema\ColumnDefinition
670
     */
671
    public function tinyIncrements($column)
672
    {
673
        return $this->unsignedTinyInteger($column, true);
674
    }
675
 
676
    /**
677
     * Create a new auto-incrementing small integer (2-byte) column on the table.
678
     *
679
     * @param  string  $column
680
     * @return \Illuminate\Database\Schema\ColumnDefinition
681
     */
682
    public function smallIncrements($column)
683
    {
684
        return $this->unsignedSmallInteger($column, true);
685
    }
686
 
687
    /**
688
     * Create a new auto-incrementing medium integer (3-byte) column on the table.
689
     *
690
     * @param  string  $column
691
     * @return \Illuminate\Database\Schema\ColumnDefinition
692
     */
693
    public function mediumIncrements($column)
694
    {
695
        return $this->unsignedMediumInteger($column, true);
696
    }
697
 
698
    /**
699
     * Create a new auto-incrementing big integer (8-byte) column on the table.
700
     *
701
     * @param  string  $column
702
     * @return \Illuminate\Database\Schema\ColumnDefinition
703
     */
704
    public function bigIncrements($column)
705
    {
706
        return $this->unsignedBigInteger($column, true);
707
    }
708
 
709
    /**
710
     * Create a new char column on the table.
711
     *
712
     * @param  string  $column
713
     * @param  int|null  $length
714
     * @return \Illuminate\Database\Schema\ColumnDefinition
715
     */
716
    public function char($column, $length = null)
717
    {
718
        $length = ! is_null($length) ? $length : Builder::$defaultStringLength;
719
 
720
        return $this->addColumn('char', $column, compact('length'));
721
    }
722
 
723
    /**
724
     * Create a new string column on the table.
725
     *
726
     * @param  string  $column
727
     * @param  int|null  $length
728
     * @return \Illuminate\Database\Schema\ColumnDefinition
729
     */
730
    public function string($column, $length = null)
731
    {
732
        $length = $length ?: Builder::$defaultStringLength;
733
 
734
        return $this->addColumn('string', $column, compact('length'));
735
    }
736
 
737
    /**
738
     * Create a new tiny text column on the table.
739
     *
740
     * @param  string  $column
741
     * @return \Illuminate\Database\Schema\ColumnDefinition
742
     */
743
    public function tinyText($column)
744
    {
745
        return $this->addColumn('tinyText', $column);
746
    }
747
 
748
    /**
749
     * Create a new text column on the table.
750
     *
751
     * @param  string  $column
752
     * @return \Illuminate\Database\Schema\ColumnDefinition
753
     */
754
    public function text($column)
755
    {
756
        return $this->addColumn('text', $column);
757
    }
758
 
759
    /**
760
     * Create a new medium text column on the table.
761
     *
762
     * @param  string  $column
763
     * @return \Illuminate\Database\Schema\ColumnDefinition
764
     */
765
    public function mediumText($column)
766
    {
767
        return $this->addColumn('mediumText', $column);
768
    }
769
 
770
    /**
771
     * Create a new long text column on the table.
772
     *
773
     * @param  string  $column
774
     * @return \Illuminate\Database\Schema\ColumnDefinition
775
     */
776
    public function longText($column)
777
    {
778
        return $this->addColumn('longText', $column);
779
    }
780
 
781
    /**
782
     * Create a new integer (4-byte) column on the table.
783
     *
784
     * @param  string  $column
785
     * @param  bool  $autoIncrement
786
     * @param  bool  $unsigned
787
     * @return \Illuminate\Database\Schema\ColumnDefinition
788
     */
789
    public function integer($column, $autoIncrement = false, $unsigned = false)
790
    {
791
        return $this->addColumn('integer', $column, compact('autoIncrement', 'unsigned'));
792
    }
793
 
794
    /**
795
     * Create a new tiny integer (1-byte) column on the table.
796
     *
797
     * @param  string  $column
798
     * @param  bool  $autoIncrement
799
     * @param  bool  $unsigned
800
     * @return \Illuminate\Database\Schema\ColumnDefinition
801
     */
802
    public function tinyInteger($column, $autoIncrement = false, $unsigned = false)
803
    {
804
        return $this->addColumn('tinyInteger', $column, compact('autoIncrement', 'unsigned'));
805
    }
806
 
807
    /**
808
     * Create a new small integer (2-byte) column on the table.
809
     *
810
     * @param  string  $column
811
     * @param  bool  $autoIncrement
812
     * @param  bool  $unsigned
813
     * @return \Illuminate\Database\Schema\ColumnDefinition
814
     */
815
    public function smallInteger($column, $autoIncrement = false, $unsigned = false)
816
    {
817
        return $this->addColumn('smallInteger', $column, compact('autoIncrement', 'unsigned'));
818
    }
819
 
820
    /**
821
     * Create a new medium integer (3-byte) column on the table.
822
     *
823
     * @param  string  $column
824
     * @param  bool  $autoIncrement
825
     * @param  bool  $unsigned
826
     * @return \Illuminate\Database\Schema\ColumnDefinition
827
     */
828
    public function mediumInteger($column, $autoIncrement = false, $unsigned = false)
829
    {
830
        return $this->addColumn('mediumInteger', $column, compact('autoIncrement', 'unsigned'));
831
    }
832
 
833
    /**
834
     * Create a new big integer (8-byte) column on the table.
835
     *
836
     * @param  string  $column
837
     * @param  bool  $autoIncrement
838
     * @param  bool  $unsigned
839
     * @return \Illuminate\Database\Schema\ColumnDefinition
840
     */
841
    public function bigInteger($column, $autoIncrement = false, $unsigned = false)
842
    {
843
        return $this->addColumn('bigInteger', $column, compact('autoIncrement', 'unsigned'));
844
    }
845
 
846
    /**
847
     * Create a new unsigned integer (4-byte) column on the table.
848
     *
849
     * @param  string  $column
850
     * @param  bool  $autoIncrement
851
     * @return \Illuminate\Database\Schema\ColumnDefinition
852
     */
853
    public function unsignedInteger($column, $autoIncrement = false)
854
    {
855
        return $this->integer($column, $autoIncrement, true);
856
    }
857
 
858
    /**
859
     * Create a new unsigned tiny integer (1-byte) column on the table.
860
     *
861
     * @param  string  $column
862
     * @param  bool  $autoIncrement
863
     * @return \Illuminate\Database\Schema\ColumnDefinition
864
     */
865
    public function unsignedTinyInteger($column, $autoIncrement = false)
866
    {
867
        return $this->tinyInteger($column, $autoIncrement, true);
868
    }
869
 
870
    /**
871
     * Create a new unsigned small integer (2-byte) column on the table.
872
     *
873
     * @param  string  $column
874
     * @param  bool  $autoIncrement
875
     * @return \Illuminate\Database\Schema\ColumnDefinition
876
     */
877
    public function unsignedSmallInteger($column, $autoIncrement = false)
878
    {
879
        return $this->smallInteger($column, $autoIncrement, true);
880
    }
881
 
882
    /**
883
     * Create a new unsigned medium integer (3-byte) column on the table.
884
     *
885
     * @param  string  $column
886
     * @param  bool  $autoIncrement
887
     * @return \Illuminate\Database\Schema\ColumnDefinition
888
     */
889
    public function unsignedMediumInteger($column, $autoIncrement = false)
890
    {
891
        return $this->mediumInteger($column, $autoIncrement, true);
892
    }
893
 
894
    /**
895
     * Create a new unsigned big integer (8-byte) column on the table.
896
     *
897
     * @param  string  $column
898
     * @param  bool  $autoIncrement
899
     * @return \Illuminate\Database\Schema\ColumnDefinition
900
     */
901
    public function unsignedBigInteger($column, $autoIncrement = false)
902
    {
903
        return $this->bigInteger($column, $autoIncrement, true);
904
    }
905
 
906
    /**
907
     * Create a new unsigned big integer (8-byte) column on the table.
908
     *
909
     * @param  string  $column
910
     * @return \Illuminate\Database\Schema\ForeignIdColumnDefinition
911
     */
912
    public function foreignId($column)
913
    {
914
        return $this->addColumnDefinition(new ForeignIdColumnDefinition($this, [
915
            'type' => 'bigInteger',
916
            'name' => $column,
917
            'autoIncrement' => false,
918
            'unsigned' => true,
919
        ]));
920
    }
921
 
922
    /**
923
     * Create a foreign ID column for the given model.
924
     *
925
     * @param  \Illuminate\Database\Eloquent\Model|string  $model
926
     * @param  string|null  $column
927
     * @return \Illuminate\Database\Schema\ForeignIdColumnDefinition
928
     */
929
    public function foreignIdFor($model, $column = null)
930
    {
931
        if (is_string($model)) {
932
            $model = new $model;
933
        }
934
 
935
        return $model->getKeyType() === 'int' && $model->getIncrementing()
936
                    ? $this->foreignId($column ?: $model->getForeignKey())
937
                    : $this->foreignUuid($column ?: $model->getForeignKey());
938
    }
939
 
940
    /**
941
     * Create a new float column on the table.
942
     *
943
     * @param  string  $column
944
     * @param  int  $total
945
     * @param  int  $places
946
     * @param  bool  $unsigned
947
     * @return \Illuminate\Database\Schema\ColumnDefinition
948
     */
949
    public function float($column, $total = 8, $places = 2, $unsigned = false)
950
    {
951
        return $this->addColumn('float', $column, compact('total', 'places', 'unsigned'));
952
    }
953
 
954
    /**
955
     * Create a new double column on the table.
956
     *
957
     * @param  string  $column
958
     * @param  int|null  $total
959
     * @param  int|null  $places
960
     * @param  bool  $unsigned
961
     * @return \Illuminate\Database\Schema\ColumnDefinition
962
     */
963
    public function double($column, $total = null, $places = null, $unsigned = false)
964
    {
965
        return $this->addColumn('double', $column, compact('total', 'places', 'unsigned'));
966
    }
967
 
968
    /**
969
     * Create a new decimal column on the table.
970
     *
971
     * @param  string  $column
972
     * @param  int  $total
973
     * @param  int  $places
974
     * @param  bool  $unsigned
975
     * @return \Illuminate\Database\Schema\ColumnDefinition
976
     */
977
    public function decimal($column, $total = 8, $places = 2, $unsigned = false)
978
    {
979
        return $this->addColumn('decimal', $column, compact('total', 'places', 'unsigned'));
980
    }
981
 
982
    /**
983
     * Create a new unsigned float column on the table.
984
     *
985
     * @param  string  $column
986
     * @param  int  $total
987
     * @param  int  $places
988
     * @return \Illuminate\Database\Schema\ColumnDefinition
989
     */
990
    public function unsignedFloat($column, $total = 8, $places = 2)
991
    {
992
        return $this->float($column, $total, $places, true);
993
    }
994
 
995
    /**
996
     * Create a new unsigned double column on the table.
997
     *
998
     * @param  string  $column
999
     * @param  int  $total
1000
     * @param  int  $places
1001
     * @return \Illuminate\Database\Schema\ColumnDefinition
1002
     */
1003
    public function unsignedDouble($column, $total = null, $places = null)
1004
    {
1005
        return $this->double($column, $total, $places, true);
1006
    }
1007
 
1008
    /**
1009
     * Create a new unsigned decimal column on the table.
1010
     *
1011
     * @param  string  $column
1012
     * @param  int  $total
1013
     * @param  int  $places
1014
     * @return \Illuminate\Database\Schema\ColumnDefinition
1015
     */
1016
    public function unsignedDecimal($column, $total = 8, $places = 2)
1017
    {
1018
        return $this->decimal($column, $total, $places, true);
1019
    }
1020
 
1021
    /**
1022
     * Create a new boolean column on the table.
1023
     *
1024
     * @param  string  $column
1025
     * @return \Illuminate\Database\Schema\ColumnDefinition
1026
     */
1027
    public function boolean($column)
1028
    {
1029
        return $this->addColumn('boolean', $column);
1030
    }
1031
 
1032
    /**
1033
     * Create a new enum column on the table.
1034
     *
1035
     * @param  string  $column
1036
     * @param  array  $allowed
1037
     * @return \Illuminate\Database\Schema\ColumnDefinition
1038
     */
1039
    public function enum($column, array $allowed)
1040
    {
1041
        return $this->addColumn('enum', $column, compact('allowed'));
1042
    }
1043
 
1044
    /**
1045
     * Create a new set column on the table.
1046
     *
1047
     * @param  string  $column
1048
     * @param  array  $allowed
1049
     * @return \Illuminate\Database\Schema\ColumnDefinition
1050
     */
1051
    public function set($column, array $allowed)
1052
    {
1053
        return $this->addColumn('set', $column, compact('allowed'));
1054
    }
1055
 
1056
    /**
1057
     * Create a new json column on the table.
1058
     *
1059
     * @param  string  $column
1060
     * @return \Illuminate\Database\Schema\ColumnDefinition
1061
     */
1062
    public function json($column)
1063
    {
1064
        return $this->addColumn('json', $column);
1065
    }
1066
 
1067
    /**
1068
     * Create a new jsonb column on the table.
1069
     *
1070
     * @param  string  $column
1071
     * @return \Illuminate\Database\Schema\ColumnDefinition
1072
     */
1073
    public function jsonb($column)
1074
    {
1075
        return $this->addColumn('jsonb', $column);
1076
    }
1077
 
1078
    /**
1079
     * Create a new date column on the table.
1080
     *
1081
     * @param  string  $column
1082
     * @return \Illuminate\Database\Schema\ColumnDefinition
1083
     */
1084
    public function date($column)
1085
    {
1086
        return $this->addColumn('date', $column);
1087
    }
1088
 
1089
    /**
1090
     * Create a new date-time column on the table.
1091
     *
1092
     * @param  string  $column
1093
     * @param  int|null  $precision
1094
     * @return \Illuminate\Database\Schema\ColumnDefinition
1095
     */
1096
    public function dateTime($column, $precision = 0)
1097
    {
1098
        return $this->addColumn('dateTime', $column, compact('precision'));
1099
    }
1100
 
1101
    /**
1102
     * Create a new date-time column (with time zone) on the table.
1103
     *
1104
     * @param  string  $column
1105
     * @param  int|null  $precision
1106
     * @return \Illuminate\Database\Schema\ColumnDefinition
1107
     */
1108
    public function dateTimeTz($column, $precision = 0)
1109
    {
1110
        return $this->addColumn('dateTimeTz', $column, compact('precision'));
1111
    }
1112
 
1113
    /**
1114
     * Create a new time column on the table.
1115
     *
1116
     * @param  string  $column
1117
     * @param  int|null  $precision
1118
     * @return \Illuminate\Database\Schema\ColumnDefinition
1119
     */
1120
    public function time($column, $precision = 0)
1121
    {
1122
        return $this->addColumn('time', $column, compact('precision'));
1123
    }
1124
 
1125
    /**
1126
     * Create a new time column (with time zone) on the table.
1127
     *
1128
     * @param  string  $column
1129
     * @param  int|null  $precision
1130
     * @return \Illuminate\Database\Schema\ColumnDefinition
1131
     */
1132
    public function timeTz($column, $precision = 0)
1133
    {
1134
        return $this->addColumn('timeTz', $column, compact('precision'));
1135
    }
1136
 
1137
    /**
1138
     * Create a new timestamp column on the table.
1139
     *
1140
     * @param  string  $column
1141
     * @param  int|null  $precision
1142
     * @return \Illuminate\Database\Schema\ColumnDefinition
1143
     */
1144
    public function timestamp($column, $precision = 0)
1145
    {
1146
        return $this->addColumn('timestamp', $column, compact('precision'));
1147
    }
1148
 
1149
    /**
1150
     * Create a new timestamp (with time zone) column on the table.
1151
     *
1152
     * @param  string  $column
1153
     * @param  int|null  $precision
1154
     * @return \Illuminate\Database\Schema\ColumnDefinition
1155
     */
1156
    public function timestampTz($column, $precision = 0)
1157
    {
1158
        return $this->addColumn('timestampTz', $column, compact('precision'));
1159
    }
1160
 
1161
    /**
1162
     * Add nullable creation and update timestamps to the table.
1163
     *
1164
     * @param  int|null  $precision
1165
     * @return void
1166
     */
1167
    public function timestamps($precision = 0)
1168
    {
1169
        $this->timestamp('created_at', $precision)->nullable();
1170
 
1171
        $this->timestamp('updated_at', $precision)->nullable();
1172
    }
1173
 
1174
    /**
1175
     * Add nullable creation and update timestamps to the table.
1176
     *
1177
     * Alias for self::timestamps().
1178
     *
1179
     * @param  int|null  $precision
1180
     * @return void
1181
     */
1182
    public function nullableTimestamps($precision = 0)
1183
    {
1184
        $this->timestamps($precision);
1185
    }
1186
 
1187
    /**
1188
     * Add creation and update timestampTz columns to the table.
1189
     *
1190
     * @param  int|null  $precision
1191
     * @return void
1192
     */
1193
    public function timestampsTz($precision = 0)
1194
    {
1195
        $this->timestampTz('created_at', $precision)->nullable();
1196
 
1197
        $this->timestampTz('updated_at', $precision)->nullable();
1198
    }
1199
 
1200
    /**
1201
     * Add a "deleted at" timestamp for the table.
1202
     *
1203
     * @param  string  $column
1204
     * @param  int|null  $precision
1205
     * @return \Illuminate\Database\Schema\ColumnDefinition
1206
     */
1207
    public function softDeletes($column = 'deleted_at', $precision = 0)
1208
    {
1209
        return $this->timestamp($column, $precision)->nullable();
1210
    }
1211
 
1212
    /**
1213
     * Add a "deleted at" timestampTz for the table.
1214
     *
1215
     * @param  string  $column
1216
     * @param  int|null  $precision
1217
     * @return \Illuminate\Database\Schema\ColumnDefinition
1218
     */
1219
    public function softDeletesTz($column = 'deleted_at', $precision = 0)
1220
    {
1221
        return $this->timestampTz($column, $precision)->nullable();
1222
    }
1223
 
1224
    /**
1225
     * Create a new year column on the table.
1226
     *
1227
     * @param  string  $column
1228
     * @return \Illuminate\Database\Schema\ColumnDefinition
1229
     */
1230
    public function year($column)
1231
    {
1232
        return $this->addColumn('year', $column);
1233
    }
1234
 
1235
    /**
1236
     * Create a new binary column on the table.
1237
     *
1238
     * @param  string  $column
1239
     * @return \Illuminate\Database\Schema\ColumnDefinition
1240
     */
1241
    public function binary($column)
1242
    {
1243
        return $this->addColumn('binary', $column);
1244
    }
1245
 
1246
    /**
1247
     * Create a new UUID column on the table.
1248
     *
1249
     * @param  string  $column
1250
     * @return \Illuminate\Database\Schema\ColumnDefinition
1251
     */
1252
    public function uuid($column = 'uuid')
1253
    {
1254
        return $this->addColumn('uuid', $column);
1255
    }
1256
 
1257
    /**
1258
     * Create a new UUID column on the table with a foreign key constraint.
1259
     *
1260
     * @param  string  $column
1261
     * @return \Illuminate\Database\Schema\ForeignIdColumnDefinition
1262
     */
1263
    public function foreignUuid($column)
1264
    {
1265
        return $this->addColumnDefinition(new ForeignIdColumnDefinition($this, [
1266
            'type' => 'uuid',
1267
            'name' => $column,
1268
        ]));
1269
    }
1270
 
1271
    /**
1272
     * Create a new ULID column on the table.
1273
     *
1274
     * @param  string  $column
1275
     * @param  int|null  $length
1276
     * @return \Illuminate\Database\Schema\ColumnDefinition
1277
     */
1278
    public function ulid($column = 'uuid', $length = 26)
1279
    {
1280
        return $this->char($column, $length);
1281
    }
1282
 
1283
    /**
1284
     * Create a new ULID column on the table with a foreign key constraint.
1285
     *
1286
     * @param  string  $column
1287
     * @param  int|null  $length
1288
     * @return \Illuminate\Database\Schema\ForeignIdColumnDefinition
1289
     */
1290
    public function foreignUlid($column, $length = 26)
1291
    {
1292
        return $this->addColumnDefinition(new ForeignIdColumnDefinition($this, [
1293
            'type' => 'char',
1294
            'name' => $column,
1295
            'length' => $length,
1296
        ]));
1297
    }
1298
 
1299
    /**
1300
     * Create a new IP address column on the table.
1301
     *
1302
     * @param  string  $column
1303
     * @return \Illuminate\Database\Schema\ColumnDefinition
1304
     */
1305
    public function ipAddress($column = 'ip_address')
1306
    {
1307
        return $this->addColumn('ipAddress', $column);
1308
    }
1309
 
1310
    /**
1311
     * Create a new MAC address column on the table.
1312
     *
1313
     * @param  string  $column
1314
     * @return \Illuminate\Database\Schema\ColumnDefinition
1315
     */
1316
    public function macAddress($column = 'mac_address')
1317
    {
1318
        return $this->addColumn('macAddress', $column);
1319
    }
1320
 
1321
    /**
1322
     * Create a new geometry column on the table.
1323
     *
1324
     * @param  string  $column
1325
     * @return \Illuminate\Database\Schema\ColumnDefinition
1326
     */
1327
    public function geometry($column)
1328
    {
1329
        return $this->addColumn('geometry', $column);
1330
    }
1331
 
1332
    /**
1333
     * Create a new point column on the table.
1334
     *
1335
     * @param  string  $column
1336
     * @param  int|null  $srid
1337
     * @return \Illuminate\Database\Schema\ColumnDefinition
1338
     */
1339
    public function point($column, $srid = null)
1340
    {
1341
        return $this->addColumn('point', $column, compact('srid'));
1342
    }
1343
 
1344
    /**
1345
     * Create a new linestring column on the table.
1346
     *
1347
     * @param  string  $column
1348
     * @return \Illuminate\Database\Schema\ColumnDefinition
1349
     */
1350
    public function lineString($column)
1351
    {
1352
        return $this->addColumn('linestring', $column);
1353
    }
1354
 
1355
    /**
1356
     * Create a new polygon column on the table.
1357
     *
1358
     * @param  string  $column
1359
     * @return \Illuminate\Database\Schema\ColumnDefinition
1360
     */
1361
    public function polygon($column)
1362
    {
1363
        return $this->addColumn('polygon', $column);
1364
    }
1365
 
1366
    /**
1367
     * Create a new geometrycollection column on the table.
1368
     *
1369
     * @param  string  $column
1370
     * @return \Illuminate\Database\Schema\ColumnDefinition
1371
     */
1372
    public function geometryCollection($column)
1373
    {
1374
        return $this->addColumn('geometrycollection', $column);
1375
    }
1376
 
1377
    /**
1378
     * Create a new multipoint column on the table.
1379
     *
1380
     * @param  string  $column
1381
     * @return \Illuminate\Database\Schema\ColumnDefinition
1382
     */
1383
    public function multiPoint($column)
1384
    {
1385
        return $this->addColumn('multipoint', $column);
1386
    }
1387
 
1388
    /**
1389
     * Create a new multilinestring column on the table.
1390
     *
1391
     * @param  string  $column
1392
     * @return \Illuminate\Database\Schema\ColumnDefinition
1393
     */
1394
    public function multiLineString($column)
1395
    {
1396
        return $this->addColumn('multilinestring', $column);
1397
    }
1398
 
1399
    /**
1400
     * Create a new multipolygon column on the table.
1401
     *
1402
     * @param  string  $column
1403
     * @return \Illuminate\Database\Schema\ColumnDefinition
1404
     */
1405
    public function multiPolygon($column)
1406
    {
1407
        return $this->addColumn('multipolygon', $column);
1408
    }
1409
 
1410
    /**
1411
     * Create a new multipolygon column on the table.
1412
     *
1413
     * @param  string  $column
1414
     * @return \Illuminate\Database\Schema\ColumnDefinition
1415
     */
1416
    public function multiPolygonZ($column)
1417
    {
1418
        return $this->addColumn('multipolygonz', $column);
1419
    }
1420
 
1421
    /**
1422
     * Create a new generated, computed column on the table.
1423
     *
1424
     * @param  string  $column
1425
     * @param  string  $expression
1426
     * @return \Illuminate\Database\Schema\ColumnDefinition
1427
     */
1428
    public function computed($column, $expression)
1429
    {
1430
        return $this->addColumn('computed', $column, compact('expression'));
1431
    }
1432
 
1433
    /**
1434
     * Add the proper columns for a polymorphic table.
1435
     *
1436
     * @param  string  $name
1437
     * @param  string|null  $indexName
1438
     * @return void
1439
     */
1440
    public function morphs($name, $indexName = null)
1441
    {
1442
        if (Builder::$defaultMorphKeyType === 'uuid') {
1443
            $this->uuidMorphs($name, $indexName);
1444
        } elseif (Builder::$defaultMorphKeyType === 'ulid') {
1445
            $this->ulidMorphs($name, $indexName);
1446
        } else {
1447
            $this->numericMorphs($name, $indexName);
1448
        }
1449
    }
1450
 
1451
    /**
1452
     * Add nullable columns for a polymorphic table.
1453
     *
1454
     * @param  string  $name
1455
     * @param  string|null  $indexName
1456
     * @return void
1457
     */
1458
    public function nullableMorphs($name, $indexName = null)
1459
    {
1460
        if (Builder::$defaultMorphKeyType === 'uuid') {
1461
            $this->nullableUuidMorphs($name, $indexName);
1462
        } elseif (Builder::$defaultMorphKeyType === 'ulid') {
1463
            $this->nullableUlidMorphs($name, $indexName);
1464
        } else {
1465
            $this->nullableNumericMorphs($name, $indexName);
1466
        }
1467
    }
1468
 
1469
    /**
1470
     * Add the proper columns for a polymorphic table using numeric IDs (incremental).
1471
     *
1472
     * @param  string  $name
1473
     * @param  string|null  $indexName
1474
     * @return void
1475
     */
1476
    public function numericMorphs($name, $indexName = null)
1477
    {
1478
        $this->string("{$name}_type");
1479
 
1480
        $this->unsignedBigInteger("{$name}_id");
1481
 
1482
        $this->index(["{$name}_type", "{$name}_id"], $indexName);
1483
    }
1484
 
1485
    /**
1486
     * Add nullable columns for a polymorphic table using numeric IDs (incremental).
1487
     *
1488
     * @param  string  $name
1489
     * @param  string|null  $indexName
1490
     * @return void
1491
     */
1492
    public function nullableNumericMorphs($name, $indexName = null)
1493
    {
1494
        $this->string("{$name}_type")->nullable();
1495
 
1496
        $this->unsignedBigInteger("{$name}_id")->nullable();
1497
 
1498
        $this->index(["{$name}_type", "{$name}_id"], $indexName);
1499
    }
1500
 
1501
    /**
1502
     * Add the proper columns for a polymorphic table using UUIDs.
1503
     *
1504
     * @param  string  $name
1505
     * @param  string|null  $indexName
1506
     * @return void
1507
     */
1508
    public function uuidMorphs($name, $indexName = null)
1509
    {
1510
        $this->string("{$name}_type");
1511
 
1512
        $this->uuid("{$name}_id");
1513
 
1514
        $this->index(["{$name}_type", "{$name}_id"], $indexName);
1515
    }
1516
 
1517
    /**
1518
     * Add nullable columns for a polymorphic table using UUIDs.
1519
     *
1520
     * @param  string  $name
1521
     * @param  string|null  $indexName
1522
     * @return void
1523
     */
1524
    public function nullableUuidMorphs($name, $indexName = null)
1525
    {
1526
        $this->string("{$name}_type")->nullable();
1527
 
1528
        $this->uuid("{$name}_id")->nullable();
1529
 
1530
        $this->index(["{$name}_type", "{$name}_id"], $indexName);
1531
    }
1532
 
1533
    /**
1534
     * Add the proper columns for a polymorphic table using ULIDs.
1535
     *
1536
     * @param  string  $name
1537
     * @param  string|null  $indexName
1538
     * @return void
1539
     */
1540
    public function ulidMorphs($name, $indexName = null)
1541
    {
1542
        $this->string("{$name}_type");
1543
 
1544
        $this->ulid("{$name}_id");
1545
 
1546
        $this->index(["{$name}_type", "{$name}_id"], $indexName);
1547
    }
1548
 
1549
    /**
1550
     * Add nullable columns for a polymorphic table using ULIDs.
1551
     *
1552
     * @param  string  $name
1553
     * @param  string|null  $indexName
1554
     * @return void
1555
     */
1556
    public function nullableUlidMorphs($name, $indexName = null)
1557
    {
1558
        $this->string("{$name}_type")->nullable();
1559
 
1560
        $this->ulid("{$name}_id")->nullable();
1561
 
1562
        $this->index(["{$name}_type", "{$name}_id"], $indexName);
1563
    }
1564
 
1565
    /**
1566
     * Adds the `remember_token` column to the table.
1567
     *
1568
     * @return \Illuminate\Database\Schema\ColumnDefinition
1569
     */
1570
    public function rememberToken()
1571
    {
1572
        return $this->string('remember_token', 100)->nullable();
1573
    }
1574
 
1575
    /**
1576
     * Add a comment to the table.
1577
     *
1578
     * @param  string  $comment
1579
     * @return \Illuminate\Support\Fluent
1580
     */
1581
    public function comment($comment)
1582
    {
1583
        return $this->addCommand('tableComment', compact('comment'));
1584
    }
1585
 
1586
    /**
1587
     * Add a new index command to the blueprint.
1588
     *
1589
     * @param  string  $type
1590
     * @param  string|array  $columns
1591
     * @param  string  $index
1592
     * @param  string|null  $algorithm
1593
     * @return \Illuminate\Support\Fluent
1594
     */
1595
    protected function indexCommand($type, $columns, $index, $algorithm = null)
1596
    {
1597
        $columns = (array) $columns;
1598
 
1599
        // If no name was specified for this index, we will create one using a basic
1600
        // convention of the table name, followed by the columns, followed by an
1601
        // index type, such as primary or index, which makes the index unique.
1602
        $index = $index ?: $this->createIndexName($type, $columns);
1603
 
1604
        return $this->addCommand(
1605
            $type, compact('index', 'columns', 'algorithm')
1606
        );
1607
    }
1608
 
1609
    /**
1610
     * Create a new drop index command on the blueprint.
1611
     *
1612
     * @param  string  $command
1613
     * @param  string  $type
1614
     * @param  string|array  $index
1615
     * @return \Illuminate\Support\Fluent
1616
     */
1617
    protected function dropIndexCommand($command, $type, $index)
1618
    {
1619
        $columns = [];
1620
 
1621
        // If the given "index" is actually an array of columns, the developer means
1622
        // to drop an index merely by specifying the columns involved without the
1623
        // conventional name, so we will build the index name from the columns.
1624
        if (is_array($index)) {
1625
            $index = $this->createIndexName($type, $columns = $index);
1626
        }
1627
 
1628
        return $this->indexCommand($command, $columns, $index);
1629
    }
1630
 
1631
    /**
1632
     * Create a default index name for the table.
1633
     *
1634
     * @param  string  $type
1635
     * @param  array  $columns
1636
     * @return string
1637
     */
1638
    protected function createIndexName($type, array $columns)
1639
    {
1640
        $index = strtolower($this->prefix.$this->table.'_'.implode('_', $columns).'_'.$type);
1641
 
1642
        return str_replace(['-', '.'], '_', $index);
1643
    }
1644
 
1645
    /**
1646
     * Add a new column to the blueprint.
1647
     *
1648
     * @param  string  $type
1649
     * @param  string  $name
1650
     * @param  array  $parameters
1651
     * @return \Illuminate\Database\Schema\ColumnDefinition
1652
     */
1653
    public function addColumn($type, $name, array $parameters = [])
1654
    {
1655
        return $this->addColumnDefinition(new ColumnDefinition(
1656
            array_merge(compact('type', 'name'), $parameters)
1657
        ));
1658
    }
1659
 
1660
    /**
1661
     * Add a new column definition to the blueprint.
1662
     *
1663
     * @param  \Illuminate\Database\Schema\ColumnDefinition  $definition
1664
     * @return \Illuminate\Database\Schema\ColumnDefinition
1665
     */
1666
    protected function addColumnDefinition($definition)
1667
    {
1668
        $this->columns[] = $definition;
1669
 
1670
        if ($this->after) {
1671
            $definition->after($this->after);
1672
 
1673
            $this->after = $definition->name;
1674
        }
1675
 
1676
        return $definition;
1677
    }
1678
 
1679
    /**
1680
     * Add the columns from the callback after the given column.
1681
     *
1682
     * @param  string  $column
1683
     * @param  \Closure  $callback
1684
     * @return void
1685
     */
1686
    public function after($column, Closure $callback)
1687
    {
1688
        $this->after = $column;
1689
 
1690
        $callback($this);
1691
 
1692
        $this->after = null;
1693
    }
1694
 
1695
    /**
1696
     * Remove a column from the schema blueprint.
1697
     *
1698
     * @param  string  $name
1699
     * @return $this
1700
     */
1701
    public function removeColumn($name)
1702
    {
1703
        $this->columns = array_values(array_filter($this->columns, function ($c) use ($name) {
1704
            return $c['name'] != $name;
1705
        }));
1706
 
1707
        return $this;
1708
    }
1709
 
1710
    /**
1711
     * Add a new command to the blueprint.
1712
     *
1713
     * @param  string  $name
1714
     * @param  array  $parameters
1715
     * @return \Illuminate\Support\Fluent
1716
     */
1717
    protected function addCommand($name, array $parameters = [])
1718
    {
1719
        $this->commands[] = $command = $this->createCommand($name, $parameters);
1720
 
1721
        return $command;
1722
    }
1723
 
1724
    /**
1725
     * Create a new Fluent command.
1726
     *
1727
     * @param  string  $name
1728
     * @param  array  $parameters
1729
     * @return \Illuminate\Support\Fluent
1730
     */
1731
    protected function createCommand($name, array $parameters = [])
1732
    {
1733
        return new Fluent(array_merge(compact('name'), $parameters));
1734
    }
1735
 
1736
    /**
1737
     * Get the table the blueprint describes.
1738
     *
1739
     * @return string
1740
     */
1741
    public function getTable()
1742
    {
1743
        return $this->table;
1744
    }
1745
 
1746
    /**
1747
     * Get the columns on the blueprint.
1748
     *
1749
     * @return \Illuminate\Database\Schema\ColumnDefinition[]
1750
     */
1751
    public function getColumns()
1752
    {
1753
        return $this->columns;
1754
    }
1755
 
1756
    /**
1757
     * Get the commands on the blueprint.
1758
     *
1759
     * @return \Illuminate\Support\Fluent[]
1760
     */
1761
    public function getCommands()
1762
    {
1763
        return $this->commands;
1764
    }
1765
 
1766
    /**
1767
     * Get the columns on the blueprint that should be added.
1768
     *
1769
     * @return \Illuminate\Database\Schema\ColumnDefinition[]
1770
     */
1771
    public function getAddedColumns()
1772
    {
1773
        return array_filter($this->columns, function ($column) {
1774
            return ! $column->change;
1775
        });
1776
    }
1777
 
1778
    /**
1779
     * Get the columns on the blueprint that should be changed.
1780
     *
1781
     * @return \Illuminate\Database\Schema\ColumnDefinition[]
1782
     */
1783
    public function getChangedColumns()
1784
    {
1785
        return array_filter($this->columns, function ($column) {
1786
            return (bool) $column->change;
1787
        });
1788
    }
1789
 
1790
    /**
1791
     * Determine if the blueprint has auto-increment columns.
1792
     *
1793
     * @return bool
1794
     */
1795
    public function hasAutoIncrementColumn()
1796
    {
1797
        return ! is_null(collect($this->getAddedColumns())->first(function ($column) {
1798
            return $column->autoIncrement === true;
1799
        }));
1800
    }
1801
 
1802
    /**
1803
     * Get the auto-increment column starting values.
1804
     *
1805
     * @return array
1806
     */
1807
    public function autoIncrementingStartingValues()
1808
    {
1809
        if (! $this->hasAutoIncrementColumn()) {
1810
            return [];
1811
        }
1812
 
1813
        return collect($this->getAddedColumns())->mapWithKeys(function ($column) {
1814
            return $column->autoIncrement === true
1815
                        ? [$column->name => $column->get('startingValue', $column->get('from'))]
1816
                        : [$column->name => null];
1817
        })->filter()->all();
1818
    }
1819
}