Update source into github
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Log;
|
||||
|
||||
use App\Models\Log;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class LogRepository extends BaseRepository implements LogRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return Log::class;
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
|
||||
{
|
||||
$model = $this->model->with($relationships)->select($select);
|
||||
|
||||
if (isset($data['customer_id'])) {
|
||||
$model = $model->where("customer_id", $data['customer_id']);
|
||||
}
|
||||
if (isset($data['relations'])) {
|
||||
foreach ($data['relations'] as $key => $value) {
|
||||
$model = $model->whereHas($key, function ($query) use ($value) {
|
||||
if (isset($value['condition'])) {
|
||||
switch (strtoupper($value['condition'])) {
|
||||
case "IN":
|
||||
$query->whereIn($value['key'], $value['value']);
|
||||
break;
|
||||
case "NotIn":
|
||||
$query->whereNotIn($value['key'], $value['value']);
|
||||
break;
|
||||
default:
|
||||
$query->where($value['key'], $value['condition'], $value['value']);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$query->where($value['key'], $value['value']);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (count($withCount) > 0) {
|
||||
$model = $model->withCount($withCount);
|
||||
}
|
||||
if(isset($data['limit']))
|
||||
{
|
||||
return $model->latest('id')->take($data['limit'])->get();
|
||||
}
|
||||
if(isset($data['page'])) {
|
||||
return $model->latest('id')->paginate(15);
|
||||
}
|
||||
|
||||
return $model->latest('id')->get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user