Skip to content

Commit

Permalink
fix: soft delete trait methods should return generic qloeuqnt builder…
Browse files Browse the repository at this point in the history
… with model
  • Loading branch information
canvural committed Jul 24, 2020
1 parent a2395c0 commit 023043b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Methods/Pipes/BuilderLocalMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use PHPStan\Type\Generic\GenericObjectType;
use function in_array;
use NunoMaduro\Larastan\Concerns;
use NunoMaduro\Larastan\Contracts\Methods\PassableContract;
Expand Down Expand Up @@ -67,7 +68,7 @@ trait_uses_recursive($classReflection->getName()), true)) {
$macro, TemplateTypeMap::createEmpty(),
array_map(function (ReflectionParameter $parameter) {
return TypehintHelper::decideTypeFromReflection($parameter->getType());
}, $parameters), new ObjectType($classReflection->getName()),
}, $parameters), new GenericObjectType(Builder::class, [new ObjectType($classReflection->getName())]),
null, null,
false, false,
false, null));
Expand Down
2 changes: 2 additions & 0 deletions tests/Application/app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App;

use Illuminate\Database\Eloquent\SoftDeletes;
use function get_class;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand All @@ -21,6 +22,7 @@
class User extends Authenticatable
{
use Notifiable;
use SoftDeletes;

/**
* The attributes that are mass assignable.
Expand Down
11 changes: 11 additions & 0 deletions tests/Features/Methods/ModelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ public function testFirstOrCreateWithRelation(User $user): Account
{
return $user->accounts()->firstOrCreate([]);
}

/** @return Builder<User> */
public function testSoftDeletesOnlyTrashed(): Builder
{
return User::onlyTrashed();
}

public function testFindOrFailWithSoftDeletesTrait(): User
{
return User::onlyTrashed()->findOrFail(5);
}
}

function foo(): string
Expand Down

0 comments on commit 023043b

Please sign in to comment.