1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of ibrand/advert. |
5
|
|
|
* |
6
|
|
|
* (c) iBrand <https://www.ibrand.cc> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace iBrand\Component\Advert\Repositories\Eloquent; |
13
|
|
|
|
14
|
|
|
use iBrand\Component\Advert\Models\AdvertItem; |
15
|
|
|
use iBrand\Component\Advert\Repositories\AdvertItemRepository; |
16
|
|
|
use Prettus\Repository\Eloquent\BaseRepository; |
17
|
|
|
use Prettus\Repository\Traits\CacheableRepository; |
18
|
|
|
use DB; |
19
|
|
|
|
20
|
|
|
class AdvertItemRepositoryEloquent extends BaseRepository implements AdvertItemRepository |
21
|
|
|
{ |
22
|
|
|
use CacheableRepository; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Specify Model class name. |
26
|
|
|
* |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
4 |
|
public function model() |
30
|
|
|
{ |
31
|
4 |
|
return AdvertItem::class; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param array $attributes |
36
|
|
|
* @param int $parentId |
37
|
|
|
* @return mixed |
38
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException |
39
|
|
|
*/ |
40
|
1 |
|
public function create(array $attributes, $parentId = 0) |
41
|
|
|
{ |
42
|
1 |
|
if ($parentId) { |
43
|
1 |
|
$attributes['parent_id'] = $parentId; |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
return parent::create($attributes); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
public function getItemsByCode($code,$associate_with = [],$depth = 0, $status = 1) |
51
|
|
|
{ |
52
|
|
|
|
53
|
3 |
|
$advert = $this->whereHas('advert', function ($query) use ($code) { |
|
|
|
|
54
|
3 |
|
return $query->where('code', $code)->where('status', $this->model()::STATUS_OPEN); |
55
|
3 |
|
})->first(); |
56
|
|
|
|
57
|
3 |
|
if (!$advert) { |
58
|
1 |
|
return null; |
59
|
|
|
} |
60
|
|
|
|
61
|
3 |
|
$query = $this->model->with('associate'); |
62
|
|
|
|
63
|
3 |
|
if (count($associate_with)>0) { |
64
|
|
|
|
65
|
1 |
|
foreach ($associate_with as $with){ |
66
|
|
|
|
67
|
1 |
|
$query = $query->with('associate.'.$with); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
3 |
|
$query = $query->where('advert_id', $advert->advert_id) |
73
|
3 |
|
->where('status', $status) |
74
|
3 |
|
->orderBy('sort'); |
75
|
|
|
|
76
|
3 |
|
if (!$depth) { |
77
|
3 |
|
$query = $query->get(); |
78
|
|
|
} else { |
79
|
1 |
|
$sub = $this->model->withDepth(); |
80
|
|
|
|
81
|
1 |
|
$query = $query->from(DB::raw("({$sub->toSql()}) as sub")) |
82
|
1 |
|
->where('depth', '<', $depth)->get(); |
83
|
|
|
} |
84
|
|
|
|
85
|
3 |
|
return $query->toTree(); |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: