Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Database\Eloquent\Relations\Concerns;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphPivot;
use Illuminate\Support\Str;

trait AsPivot
Expand Down Expand Up @@ -166,13 +167,13 @@ protected function getDeleteQuery()
*/
public function getTable()
{
if (! isset($this->table)) {
if (! isset($this->table) && (! $this instanceof MorphPivot)) {
$this->setTable(str_replace(
'\\', '', Str::snake(Str::singular(class_basename($this)))
));
}

return $this->table;
return parent::getTable();
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/Database/DatabaseEloquentIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2834,10 +2834,14 @@ public function parentPost()

public function tags()
{
return $this->morphToMany(EloquentTestTag::class, 'taggable', null, null, 'tag_id')->withPivot('taxonomy');
return $this->morphToMany(EloquentTestTag::class, 'taggable', Taggable::class, null, 'tag_id')->withPivot('taxonomy');
}
}

class Taggable extends MorphPivot
{
}

class EloquentTestTag extends Eloquent
{
protected $table = 'tags';
Expand Down
Loading