/
marklis
/
transport
Обзор
Документация
Войти
/
marklis
/
transport
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/Repositories/MessageRepository.php
76 строк
2 KB
Мамонов Алексей Анатольевич
Пагинация и другое
04 мар 2025, 16:27
04 мар 2025, 16:27
59a0854
Код
Авторство
О чём код?
<?php namespace App\Repositories; use App\Contracts\Repositories\MessageRepositoryContract; use App\Models\Message as Model; use Illuminate\Support\Collection; use Illuminate\Pagination\LengthAwarePaginator; class MessageRepository extends EntityRepository implements MessageRepositoryContract { public function __construct(Model $model) { parent::__construct($model); } public function getWithTrashed( array|Collection $columns = [], array|Collection $parameters = [], string|null $orderBy = null, string $sortingDirection = 'asc' ): Collection { $query = $this->model; if ($columns) { $query = $query->select($columns); } if ($parameters) { foreach ($parameters as $key => $parameter) { if (is_array($parameter)) { $query = $query->whereIn($key, $parameter); } else { $query = $query->where($key, $parameter); } } } if ($orderBy) { $query = $query->orderBy($orderBy, $sortingDirection); } return $query->withTrashed()->get(); } public function paginateWithTrashed( array|Collection $columns = [], array|Collection $parameters = [], int $perPage = 20, string|null $orderBy = null, string $sortingDirection = 'asc' ): LengthAwarePaginator { $query = $this->model; if ($columns) { $query = $query->select($columns); } if ($parameters) { foreach ($parameters as $key => $parameter) { if (is_array($parameter)) { $query = $query->whereIn($key, $parameter); } else { $query = $query->where($key, $parameter); } } } if ($orderBy) { $query = $query->orderBy($orderBy, $sortingDirection); } return $query->withTrashed()->paginate($perPage); } public function deleteUnsent(): void { $messages = $this->get([], ['deleted_at' => null]); foreach ($messages as $message) { $message->forceDelete(); } } }