demo/app/Modules/User/Tasks/FindTask.php
2023-03-23 18:50:47 +01:00

72 lines
1.6 KiB
PHP

<?php
namespace LaraBB\User\Tasks;
use Illuminate\Database\Eloquent\Collection;
use LaraBB\User\Models\User;
/**
* Class GetUserTask
* @package LaraBB\User\Tasks
*/
class FindTask
{
/**
* GetUserTask constructor.
* @param User $user
*/
public function __construct(private readonly User $user)
{
}
/**
* @param array $with
* @return Collection|array
*/
public function all(array $with = []): Collection|array
{
return $this->user->query()->with($with)->get();
}
/**
* @param string $uuid
* @param array $with
* @return User
*/
public function byUuid(string $uuid, array $with = []): User
{
return $this->user->query()->where('uuid', $uuid)->with($with)->get()->first();
}
/**
* @param string $username
* @param array $with
* @return User
*/
public function byUsername(string $username, array $with = []): User
{
return $this->user->query()->where('username', $username)->with($with)->get()->first();
}
/**
* @param string $email
* @param array $with
* @return User
*/
public function byEmail(string $email, array $with = []): User
{
return $this->user->query()->where('email_hashed', hash('sha512', $email))->with($with)->get()->first();
}
/**
* @param string $pid
* @param array $with
* @return User|null
*/
public function byPid(string $pid, array $with = []): User|null
{
return $this->user->query()->where('pid', $pid)->with($with)->get()->first();
}
}