Skip to content

Commit

Permalink
Merge pull request #68 from giacomomasseron/models-name-in-config
Browse files Browse the repository at this point in the history
add models name in config file
  • Loading branch information
ousid authored Sep 9, 2024
2 parents bb80702 + 1598ff7 commit 8073191
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
10 changes: 9 additions & 1 deletion config/laravel_ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,13 @@
],
],
],

/**
* Models for Eloquent relationships
*/
'models' => [
'ticket' => \Coderflex\LaravelTicket\Models\Ticket::class,
'message' => \Coderflex\LaravelTicket\Models\Message::class,
'category' => \Coderflex\LaravelTicket\Models\Category::class,
'label' => \Coderflex\LaravelTicket\Models\Label::class,
]
];
2 changes: 1 addition & 1 deletion src/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Category extends Model
*/
public function tickets(): BelongsToMany
{
return $this->belongsToMany(Ticket::class);
return $this->belongsToMany(config('laravel_ticket.models.ticket'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Label extends Model
*/
public function tickets(): BelongsToMany
{
return $this->belongsToMany(Ticket::class);
return $this->belongsToMany(config('laravel_ticket.models.ticket'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function ticket(): BelongsTo
$tableName = config('laravel_ticket.table_names.messages', 'messages');

return $this->belongsTo(
Ticket::class,
config('laravel_ticket.models.ticket'),
$tableName['columns']['ticket_foreign_id']
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Models/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function messages(): HasMany
$tableName = config('laravel_ticket.table_names.messages', 'messages');

return $this->hasMany(
Message::class,
config('laravel_ticket.models.message'),
(string) $tableName['columns']['ticket_foreign_id'],
);
}
Expand All @@ -74,7 +74,7 @@ public function categories(): BelongsToMany
$table = config('laravel_ticket.table_names.category_ticket', 'category_ticket');

return $this->belongsToMany(
Category::class,
config('laravel_ticket.models.category'),
$table['table'],
$table['columns']['ticket_foreign_id'],
$table['columns']['category_foreign_id'],
Expand All @@ -89,7 +89,7 @@ public function labels(): BelongsToMany
$table = config('laravel_ticket.table_names.label_ticket', 'label_ticket');

return $this->belongsToMany(
Label::class,
config('laravel_ticket.models.label'),
$table['table'],
$table['columns']['ticket_foreign_id'],
$table['columns']['label_foreign_id'],
Expand All @@ -104,7 +104,7 @@ public function labels(): BelongsToMany
public function getTable()
{
return config(
'laravel_ticket.table_names.tickets',
'laravel_ticket.models.tickets',
parent::getTable()
);
}
Expand Down

0 comments on commit 8073191

Please sign in to comment.