1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace App\Repositories;
- use App\Models\ArticleCategory;
- use Prettus\Repository\Eloquent\BaseRepository;
- /**
- * Class ArticleCategoryRepositoryEloquent.
- *
- * @package namespace App\Repositories;
- */
- class ArticleCategoryRepository extends BaseRepository
- {
- /**
- * Specify Model class name
- *
- * @return string
- */
- public function model()
- {
- return ArticleCategory::class;
- }
- /**
- * @param $where array $limit int
- * @return null|\Illuminate\Database\Eloquent\Model
- */
- public function getChildCategorys($where, $limit)
- {
- return $this->model->where($where)->orderBy('list_order', 'desc')->orderBy('created_at', 'desc')->limit($limit)->get();
- }
- public function getInfo($id)
- {
- $info = $this->model->where('id', $id)->first();
- return $info;
- }
- public function getBread($id)
- {
- $info = $this->model->where('id', $id)->first();
- $res = [['id' => $info['id'], 'name' => $info['category_name']]];
- if ($info['parent_id'] != 0) {
- $this->_getBread($info, $res);
- }
- return $res;
- }
- private function _getBread($info, &$res)
- {
- $cate = $this->model->where('id', $info['parent_id'])->first();
- array_unshift($res, ['id' => $cate['id'], 'name' => $cate['category_name']]);
- if ($cate['parent_id'] != 0) {
- $this->_getBread($cate, $res);
- }
- }
- }
|