Skip to content

Commit

Permalink
Add custom table name support to model
Browse files Browse the repository at this point in the history
  • Loading branch information
tjardoo committed Sep 28, 2023
1 parent caf712b commit 796f481
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Http/Controllers/MailViewerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function show(string $uuid): Response

public function analytics(): View
{
$items = DB::table('mail_viewer_items')
$items = DB::table(config('mailviewer.table_name'))
->whereNotNull('notification')
->select([
DB::raw('notification AS name'),
Expand Down
8 changes: 8 additions & 0 deletions src/Models/MailViewerItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class MailViewerItem extends Model
{
use HasFactory;

public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$this->setTable(config('mailviewer.table_name', 'mail_viewer_items'));
$this->setConnection(config('mailviewer.database_connection', 'mysql'));
}

public static function booted(): void
{
static::creating(function (self $mailViewerItem) {
Expand Down

0 comments on commit 796f481

Please sign in to comment.