update deploy
This commit is contained in:
46
app/Repositories/Eloquent/UserRepository.php
Normal file
46
app/Repositories/Eloquent/UserRepository.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Eloquent;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Repositories\Contracts\UserRepositoryInterface;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* @extends BaseRepository<User>
|
||||
*/
|
||||
class UserRepository extends BaseRepository implements UserRepositoryInterface
|
||||
{
|
||||
public function __construct(User $model)
|
||||
{
|
||||
parent::__construct($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $filters
|
||||
* @return LengthAwarePaginator<int, User>
|
||||
*/
|
||||
public function paginate(array $filters = [], int $perPage = 15): LengthAwarePaginator
|
||||
{
|
||||
$query = $this->model->newQuery()->with('roles');
|
||||
|
||||
if (! empty($filters['search'])) {
|
||||
$search = $filters['search'];
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'like', "%{$search}%")
|
||||
->orWhere('email', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
if (! empty($filters['role'])) {
|
||||
$query->role($filters['role']);
|
||||
}
|
||||
|
||||
return $query->latest()->paginate($perPage);
|
||||
}
|
||||
|
||||
public function findByEmail(string $email): ?User
|
||||
{
|
||||
return $this->model->newQuery()->where('email', $email)->first();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user