I'm currently running Larastan version 2.4.0 and have also ran the `./vendor/bin/phpstan clear-result-cache`` but still getting the same error being reported.
Does anyone know why this error would be reported.
:34 Parameter #1 $callback of method
Illuminate\Support\Collection<int,Illuminate\Database\Eloquent\Model>::each() expects
callable(Illuminate\Database\Eloquent\Model, int): mixed, Closure(App\Models\User): mixed
given.
if ($group->potentialMembers>isNotEmpty()) {
$group->potentialMembers->each(
fn (\App\Models\User $user, int $key) => UserJoinGroupAction::run($user, $group, $startDate)
);
}
UserJoinGroupAction
<?php
declare(strict_types=1);
namespace App\Actions\Groups;
use App\Actions\Users\UserJoinTeamAction;
use App\Exceptions\CannotBeActivatedException;
use App\Models\Group;
use App\Models\User;
use Illuminate\Support\Carbon;
use Lorisleiva\Actions\Concerns\AsAction;
class ActivateGroupAction extends BaseGroupAction
{
use AsAction;
/**
* Activate a group.
*
*/
public function handle(Group $group, ?Carbon $startDate = null): void
{
throw_if($group->canBeActivated(), CannotBeActivatedException::class);
$startDate ??= now();
if ($group->potentialMembers->isNotEmpty()) {
$group->potentialMembers->each(
fn (User $user, int $key) => UserJoinGroupAction::run($user, $group, $startDate)
);
}
$this->groupRepository->activate($group, $startDate);
}
}
<?php
declare(strict_types=1);
namespace App\Actions\Users;
use App\Models\User;
use Illuminate\Support\Carbon;
use Lorisleiva\Actions\Concerns\AsAction;
class UserJoinGroupAction extends BaseUserAction
{
use AsAction;
/**
* EUser can join goup.
*/
public function handle(User $user, Group, $group, ?Carbon $startDate = null): void
{
$startDate ??= now();
$this->userRepository->joinGroup($user, $group, $startDate);
}
}
Group
public function potentialMembers(): MorphToMany
{
return $this->morphedByMany(User::class, 'member')
->using(GroupMember::class)
->withPivot(['joined_at', 'left_at']);
}