54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Models\SousTraitant;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
|
class SousTraitantRepository extends BaseRepository implements SousTraitantRepositoryInterface
|
|
{
|
|
public function __construct(SousTraitant $model)
|
|
{
|
|
parent::__construct($model);
|
|
}
|
|
|
|
/**
|
|
* Get paginated sous-traitants.
|
|
*/
|
|
public function paginate(int $perPage = 15, array $filters = []): LengthAwarePaginator
|
|
{
|
|
$query = $this->model->newQuery();
|
|
|
|
if (!empty($filters['search'])) {
|
|
$query->where(function ($q) use ($filters) {
|
|
$q->where('nom_entreprise', 'like', '%' . $filters['search'] . '%')
|
|
->orWhere('contact_principal', 'like', '%' . $filters['search'] . '%')
|
|
->orWhere('email', 'like', '%' . $filters['search'] . '%')
|
|
->orWhere('siret', 'like', '%' . $filters['search'] . '%')
|
|
->orWhere('numero_contrat', 'like', '%' . $filters['search'] . '%')
|
|
->orWhere('type_prestation', 'like', '%' . $filters['search'] . '%');
|
|
});
|
|
}
|
|
|
|
if (!empty($filters['statut'])) {
|
|
$query->where('statut', $filters['statut']);
|
|
}
|
|
|
|
$sortField = $filters['sort_by'] ?? 'created_at';
|
|
$sortDirection = $filters['sort_direction'] ?? 'desc';
|
|
$query->orderBy($sortField, $sortDirection);
|
|
|
|
return $query->paginate($perPage);
|
|
}
|
|
|
|
public function searchByName(string $name)
|
|
{
|
|
return $this->model
|
|
->newQuery()
|
|
->where('nom_entreprise', 'like', '%' . $name . '%')
|
|
->get();
|
|
}
|
|
}
|