We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7fec017 commit e3da417Copy full SHA for e3da417
src/Generators/FactoryGenerator.php
@@ -198,11 +198,11 @@ protected function buildDefinition(Model $model)
198
$definition
199
);
200
} elseif (in_array($column->dataType(), ['json', 'jsonb'])) {
201
- $default = $column->defaultValue() ?? "'{}'";
+ $default = $column->defaultValue() ?? "{}";
202
if (Blueprint::isLaravel8OrHigher()) {
203
- $definition .= str_repeat(self::INDENT, 3) . "'{$column->name()}' => {$default}," . PHP_EOL;
+ $definition .= str_repeat(self::INDENT, 3) . "'{$column->name()}' => '{$default}'," . PHP_EOL;
204
} else {
205
- $definition .= str_repeat(self::INDENT, 2) . "'{$column->name()}' => {$default}," . PHP_EOL;
+ $definition .= str_repeat(self::INDENT, 2) . "'{$column->name()}' => '{$default}'," . PHP_EOL;
206
}
207
} elseif ($column->dataType() === 'morphs') {
208
if ($column->isNullable()) {
src/Generators/MigrationGenerator.php
@@ -198,7 +198,7 @@ protected function buildDefinition(Model $model)
foreach ($modifiers as $modifier) {
if (is_array($modifier)) {
- $column_definition .= '->'.key($modifier).'('.current($modifier).')';
+ $column_definition .= sprintf("->%s('%s')", key($modifier), addslashes(current($modifier)));
} elseif ($modifier === 'unsigned' && Str::startsWith($dataType, 'unsigned')) {
continue;
} elseif ($modifier === 'nullable' && Str::startsWith($dataType, 'nullable')) {
src/Lexers/ModelLexer.php
@@ -241,10 +241,10 @@ private function buildColumn(string $name, string $definition)
241
242
if (isset(self::$modifiers[strtolower($value)])) {
243
$modifierAttributes = $parts[1] ?? null;
244
- if ($modifierAttributes === null) {
+ if (is_null($modifierAttributes)) {
245
$modifiers[] = self::$modifiers[strtolower($value)];
246
247
- $modifiers[] = [self::$modifiers[strtolower($value)] => $modifierAttributes];
+ $modifiers[] = [self::$modifiers[strtolower($value)] => preg_replace('~^[\'"]?(.*?)[\'"]?$~', '$1', $modifierAttributes)];
248
249
250
tests/Feature/Generators/MigrationGeneratorTest.php
@@ -790,6 +790,7 @@ public function modelTreeDataProvider()
790
['drafts/with-timezones.yaml', 'database/migrations/timestamp_create_comments_table.php', 'migrations/with-timezones.php'],
791
['drafts/relationships.yaml', 'database/migrations/timestamp_create_comments_table.php', 'migrations/relationships.php'],
792
['drafts/indexes.yaml', 'database/migrations/timestamp_create_posts_table.php', 'migrations/indexes.php'],
793
+ ['drafts/custom-indexes.yaml', 'database/migrations/timestamp_create_cooltables_table.php', 'migrations/custom-indexes.php'],
794
['drafts/unconventional.yaml', 'database/migrations/timestamp_create_teams_table.php', 'migrations/unconventional.php'],
795
['drafts/optimize.yaml', 'database/migrations/timestamp_create_optimizes_table.php', 'migrations/optimize.php'],
796
['drafts/model-key-constraints.yaml', 'database/migrations/timestamp_create_orders_table.php', 'migrations/model-key-constraints.php'],
tests/Feature/Lexers/ModelLexerTest.php
@@ -664,11 +664,12 @@ public function modifierAttributesProvider()
664
['default:0.00', 'default', 0.00],
665
['default:0', 'default', 0],
666
['default:string', 'default', 'string'],
667
- ["default:'empty'", 'default', "'empty'"],
668
- ['default:""', 'default', '""'],
+ ["default:'empty'", 'default', 'empty'],
+ ['default:""', 'default', ''],
669
['charset:utf8', 'charset', 'utf8'],
670
['collation:utf8_unicode', 'collation', 'utf8_unicode'],
671
- ['default:"space between"', 'default', '"space between"'],
+ ['default:"space between"', 'default', 'space between'],
672
+ ["default:'[]'", 'default', '[]'],
673
];
674
675
tests/fixtures/drafts/custom-indexes.yaml
@@ -0,0 +1,5 @@
1
+models:
2
+ cooltable:
3
+ timestamps: false
4
+ coolcool: id foreign:coolcool.id index:custom_index_coolcool
5
+ foobar: id foreign:foobars.id index:custom_index_foobar
tests/fixtures/migrations/columns-with-comments.php
@@ -15,7 +15,7 @@ public function up()
15
{
16
Schema::create('professions', function (Blueprint $table) {
17
$table->id();
18
- $table->string('title', 400)->comment("Some title for the profession");
+ $table->string('title', 400)->comment('Some title for the profession');
19
$table->string('description', 400)->nullable()->comment('Some description for the profession');
20
$table->timestamps();
21
});
tests/fixtures/migrations/custom-indexes.php
@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
6
7
+class CreateCooltablesTable extends Migration
8
+{
9
+ /**
10
+ * Run the migrations.
11
+ *
12
+ * @return void
13
+ */
14
+ public function up()
+ {
+ Schema::disableForeignKeyConstraints();
+ Schema::create('cooltables', function (Blueprint $table) {
+ $table->id();
+ $table->foreignId('coolcool')->constrained('coolcool')->cascadeOnDelete()->index('custom_index_coolcool');
+ $table->foreignId('foobar')->constrained('foobars')->cascadeOnDelete()->index('custom_index_foobar');
22
+ });
23
24
+ Schema::enableForeignKeyConstraints();
25
+ }
26
27
28
+ * Reverse the migrations.
29
30
31
32
+ public function down()
33
34
+ Schema::dropIfExists('cooltables');
35
36
+}
0 commit comments