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

51 lines
1.1 KiB
PHP

<?php
namespace LaraBB\Category\Tasks;
use Illuminate\Database\Eloquent\Collection;
use LaraBB\Category\Models\Category;
/**
* Class GetCategoryTask
* @package LaraBB\Category\Tasks
*/
class FindTask
{
/**
* GetCategoryTask constructor.
* @param Category $category
*/
public function __construct(private readonly Category $category)
{
}
/**
* @param array $with
* @return Collection|array
*/
public function all(array $with = []): Collection|array
{
return $this->category->query()->with($with)->get();
}
/**
* @param string $uuid
* @param array $with
* @return Category
*/
public function byUuid(string $uuid, array $with = []): Category
{
return $this->category->query()->with($with)->where('uuid', $uuid)->get()->first();
}
/**
* @param string $slug
* @param array $with
* @return Category
*/
public function bySlug(string $slug, array $with = []): Category
{
return $this->category->query()->with($with)->where('slug', $slug)->get()->first();
}
}