58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Menu;
|
|
|
|
use App\Models\Menu;
|
|
use App\Models\Payment;
|
|
use App\Repositories\BaseRepository;
|
|
|
|
class MenuRepository extends BaseRepository implements MenuRepositoryInterface
|
|
{
|
|
public function getModel()
|
|
{
|
|
return Menu::class;
|
|
}
|
|
|
|
public function filter(array $filters)
|
|
{
|
|
$query = $this->model->query();
|
|
|
|
if (isset($data['is_active'])) {
|
|
$query->where('is_active', $data['is_active']);
|
|
}
|
|
|
|
if (isset($data['title'])) {
|
|
$query->where('title', 'like', '%' . $data['title'] . '%');
|
|
}
|
|
|
|
return $query->defaultOrder()->paginate(10);
|
|
}
|
|
|
|
|
|
public function store(array $data)
|
|
{
|
|
if (isset($data['parent_id']) && $data['parent_id']) {
|
|
$parent = $this->model->findOrFail($data['parent_id']);
|
|
return $parent->children()->create($data);
|
|
} else {
|
|
return $this->model->create($data);
|
|
}
|
|
}
|
|
|
|
public function getMenuParent($excludeId = null)
|
|
{
|
|
$query = $this->model->query();
|
|
|
|
if ($excludeId) {
|
|
$query->where('id', '!=', $excludeId);
|
|
}
|
|
|
|
return $query->get();
|
|
}
|
|
|
|
public function getTree()
|
|
{
|
|
return $this->model->defaultOrder()->get()->toTree();
|
|
}
|
|
}
|