Skip to content
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
1 change: 1 addition & 0 deletions config/laravel_ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*/
'columns' => [
'ticket_foreing_id' => 'ticket_id',
'user_foreign_id' => 'user_id',
],
],
/**
Expand Down
2 changes: 1 addition & 1 deletion database/migrations/create_messages_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ return new class extends Migration

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

namespace Coderflex\LaravelTicket\Models;

use App\Models\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand Down Expand Up @@ -38,6 +39,21 @@ public function ticket(): BelongsTo
);
}

/**
* Get User RelationShip
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user(): BelongsTo
{
$tableName = config('laravel_ticket.table_names.messages', 'messages');

return $this->belongsTo(
User::class,
$tableName['columns']['user_foreing_id']
);
}

/**
* Get the table associated with the model.
*
Expand Down