Skip to content

Commit

Permalink
Merge pull request #50 from DannyCooper/foreign-fix
Browse files Browse the repository at this point in the history
fix typo in foreign
  • Loading branch information
ousid committed Jan 10, 2024
2 parents 6bdb631 + 0e67dec commit 771101b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions config/laravel_ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
'messages' => [
'table' => 'messages',
/**
* This is the foreing key for associated to the ticket
* This is the foreign key for associated to the ticket
* If you renamed the ticket table, you should consider
* changing this column as well to follow the laravel
* convention, "table_id"
*
* @see https://laravel.com/docs/9.x/eloquent-relationships#one-to-many
*/
'columns' => [
'user_foreing_id' => 'user_id',
'ticket_foreing_id' => 'ticket_id',
'user_foreign_id' => 'user_id',
'ticket_foreign_id' => 'ticket_id',
],
],
/**
Expand Down
4 changes: 2 additions & 2 deletions database/migrations/create_messages_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ return new class extends Migration

Schema::create($tableName['table'], function (Blueprint $table) use ($tableName) {
$table->id();
$table->foreignId($tableName['columns']['user_foreing_id']);
$table->foreignId($tableName['columns']['ticket_foreing_id']);
$table->foreignId($tableName['columns']['user_foreign_id']);
$table->foreignId($tableName['columns']['ticket_foreign_id']);
$table->text('message');
$table->timestamps();
});
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function ticket(): BelongsTo

return $this->belongsTo(
Ticket::class,
$tableName['columns']['ticket_foreing_id']
$tableName['columns']['ticket_foreign_id']
);
}

Expand All @@ -45,7 +45,7 @@ public function user(): BelongsTo

return $this->belongsTo(
config('auth.providers.users.model'),
$tableName['columns']['user_foreing_id']
$tableName['columns']['user_foreign_id']
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function messages(): HasMany

return $this->hasMany(
Message::class,
(string) $tableName['columns']['ticket_foreing_id'],
(string) $tableName['columns']['ticket_foreign_id'],
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Factories/MessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function definition()

return [
'user_id' => User::factory(),
$tableName['columns']['ticket_foreing_id'] => Ticket::factory(),
$tableName['columns']['ticket_foreign_id'] => Ticket::factory(),
'message' => $this->faker->paragraph(2),
];
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

$message = Message::factory()
->create([
$tableName['columns']['ticket_foreing_id'] => $ticket->id,
$tableName['columns']['ticket_foreign_id'] => $ticket->id,
'message' => 'Message from a ticket',
]);

$this->assertDatabaseHas($tableName['table'], [
$tableName['columns']['ticket_foreing_id'] => $ticket->id,
$tableName['columns']['ticket_foreign_id'] => $ticket->id,
'message' => 'Message from a ticket',
]);

Expand Down

0 comments on commit 771101b

Please sign in to comment.