Skip to content

Oasin #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions config/laravel_ticket.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
declare(strict_types=1);

use Coderflex\LaravelTicket\Models\Category;
use Coderflex\LaravelTicket\Models\Label;
use Coderflex\LaravelTicket\Models\Message;
use Coderflex\LaravelTicket\Models\Ticket;

return [
/*
Expand All @@ -12,6 +18,13 @@
| instruction before you change the values.
|
*/
'models' => [
'ticket' => Ticket::class,
'message' => Message::class,
'category' => Category::class,
'labels' => Label::class
],

'table_names' => [
/**
* Tickets table
Expand All @@ -20,16 +33,16 @@
/**
* Categories table for the tickets
*/
'categories' => 'categories',
'categories' => 'ticket_categories',
/**
* Labels table for the tickets
*/
'labels' => 'labels',
'labels' => 'ticket_labels',
/**
* Messages table to appears in the ticket
* Messages table to appear in the ticket
*/
'messages' => [
'table' => 'messages',
'table' => 'ticket_messages',
/**
* This is the foreing key for associated to the ticket
* If you renamed the ticket table, you should consider
Expand All @@ -52,7 +65,7 @@
* @see https://laravel.com/docs/9.x/eloquent-relationships#many-to-many
*/
'label_ticket' => [
'table' => 'label_ticket',
'table' => 'ticket_label',
'columns' => [
'label_foreign_id' => 'label_id',
'ticket_foreign_id' => 'ticket_id',
Expand All @@ -66,7 +79,7 @@
* @see https://laravel.com/docs/9.x/eloquent-relationships#many-to-many
*/
'category_ticket' => [
'table' => 'category_ticket',
'table' => 'ticket_category',
'columns' => [
'category_foreign_id' => 'category_id',
'ticket_foreign_id' => 'ticket_id',
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/HasTickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ trait HasTickets
*/
public function tickets(): HasMany
{
return $this->hasMany(Ticket::class, 'user_id');
return $this->hasMany(config('laravel_ticket.models.ticket', Ticket::class), 'user_id');
}

/**
* Get User tickets relationship
*/
public function messages(): HasMany
{
return $this->hasMany(Message::class, 'user_id');
return $this->hasMany(config('laravel_ticket.models.message', Message::class), 'user_id');
}
}
15 changes: 11 additions & 4 deletions src/Concerns/InteractsWithTickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function isOpen(): bool
*/
public function isClosed(): bool
{
return ! $this->isOpen();
return !$this->isOpen();
}

/**
Expand All @@ -81,7 +81,7 @@ public function isResolved(): bool
*/
public function isUnresolved(): bool
{
return ! $this->isResolved();
return !$this->isResolved();
}

/**
Expand All @@ -97,7 +97,7 @@ public function isLocked(): bool
*/
public function isUnlocked(): bool
{
return ! $this->isLocked();
return !$this->isLocked();
}

/**
Expand Down Expand Up @@ -190,8 +190,15 @@ public function reopenAsUnresolved(): self
*/
public function assignTo(Model|int $user): self
{

if ($user instanceof Model) {
$id = $user->getKey();
}else{
$id = $user;
}

$this->update([
'assigned_to' => $user,
'assigned_to' => $id,
]);

return $this;
Expand Down
1 change: 1 addition & 0 deletions src/Enums/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ enum Status: string
{
case OPEN = 'open';
case CLOSED = 'closed';
case ANSWERED = 'answered';
case ARCHIVED = 'archived';
}
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', Ticket::class));
}

/**
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', Ticket::class));
}

/**
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', Ticket::class),
$tableName['columns']['ticket_foreing_id']
);
}
Expand Down
6 changes: 3 additions & 3 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', Message::class),
(string) $tableName['columns']['ticket_foreing_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', Category::class),
$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', Label::class),
$table['table'],
$table['columns']['ticket_foreign_id'],
$table['columns']['label_foreign_id'],
Expand Down