Skip to content

Revert "[12.x] use "class-string" type for using pivot model" #55079

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 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ protected function newMorphMany(Builder $query, Model $parent, $type, $id, $loca
* @param string|null $parentKey
* @param string|null $relatedKey
* @param string|null $relation
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<TRelatedModel, $this, \Illuminate\Database\Eloquent\Relations\Pivot>
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<TRelatedModel, $this>
*/
public function belongsToMany(
$related,
Expand Down Expand Up @@ -624,7 +624,7 @@ public function belongsToMany(
* @param string $parentKey
* @param string $relatedKey
* @param string|null $relationName
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<TRelatedModel, TDeclaringModel, \Illuminate\Database\Eloquent\Relations\Pivot>
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<TRelatedModel, TDeclaringModel>
*/
protected function newBelongsToMany(
Builder $query,
Expand Down
7 changes: 3 additions & 4 deletions src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
/**
* @template TRelatedModel of \Illuminate\Database\Eloquent\Model
* @template TDeclaringModel of \Illuminate\Database\Eloquent\Model
* @template TPivotModel of \Illuminate\Database\Eloquent\Relations\Pivot
*
* @extends \Illuminate\Database\Eloquent\Relations\Relation<TRelatedModel, TDeclaringModel, \Illuminate\Database\Eloquent\Collection<int, TRelatedModel>>
*/
Expand Down Expand Up @@ -129,7 +128,7 @@ class BelongsToMany extends Relation
/**
* The class name of the custom pivot model to use for the relationship.
*
* @var class-string<TPivotModel>
* @var string
*/
protected $using;

Expand Down Expand Up @@ -317,7 +316,7 @@ protected function buildDictionary(EloquentCollection $results)
/**
* Get the class being used for pivot models.
*
* @return class-string<TPivotModel>
* @return string
*/
public function getPivotClass()
{
Expand All @@ -327,7 +326,7 @@ public function getPivotClass()
/**
* Specify the custom pivot model to use for the relationship.
*
* @param class-string<TPivotModel> $class
* @param string $class
* @return $this
*/
public function using($class)
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @template TRelatedModel of \Illuminate\Database\Eloquent\Model
* @template TDeclaringModel of \Illuminate\Database\Eloquent\Model
*
* @extends \Illuminate\Database\Eloquent\Relations\BelongsToMany<TRelatedModel, TDeclaringModel, \Illuminate\Database\Eloquent\Relations\Pivot>
* @extends \Illuminate\Database\Eloquent\Relations\BelongsToMany<TRelatedModel, TDeclaringModel>
*/
class MorphToMany extends BelongsToMany
{
Expand Down
6 changes: 3 additions & 3 deletions types/Database/Eloquent/Relations.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function test(User $user, Post $post, Comment $comment, ChildUser $child): void
assertType('Illuminate\Types\Relations\Post|false', $user->posts()->save(new Post()));
assertType('Illuminate\Types\Relations\Post|false', $user->posts()->saveQuietly(new Post()));

assertType('Illuminate\Database\Eloquent\Relations\BelongsToMany<Illuminate\Types\Relations\Role, Illuminate\Types\Relations\User, Illuminate\Database\Eloquent\Relations\Pivot>', $user->roles());
assertType('Illuminate\Database\Eloquent\Relations\BelongsToMany<Illuminate\Types\Relations\Role, Illuminate\Types\Relations\User>', $user->roles());
assertType('Illuminate\Database\Eloquent\Collection<int, Illuminate\Types\Relations\Role>', $user->roles()->getResults());
assertType('Illuminate\Database\Eloquent\Collection<int, Illuminate\Types\Relations\Role>', $user->roles()->find([1]));
assertType('Illuminate\Database\Eloquent\Collection<int, Illuminate\Types\Relations\Role>', $user->roles()->findMany([1, 2, 3]));
Expand Down Expand Up @@ -157,11 +157,11 @@ public function latestPost(): HasOne
return $post;
}

/** @return BelongsToMany<Role, $this, \Illuminate\Database\Eloquent\Relations\Pivot> */
/** @return BelongsToMany<Role, $this> */
public function roles(): BelongsToMany
{
$belongsToMany = $this->belongsToMany(Role::class);
assertType('Illuminate\Database\Eloquent\Relations\BelongsToMany<Illuminate\Types\Relations\Role, $this(Illuminate\Types\Relations\User), Illuminate\Database\Eloquent\Relations\Pivot>', $belongsToMany);
assertType('Illuminate\Database\Eloquent\Relations\BelongsToMany<Illuminate\Types\Relations\Role, $this(Illuminate\Types\Relations\User)>', $belongsToMany);

return $belongsToMany;
}
Expand Down
Loading