123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Repositories\Models\Inform;
- use App\Repositories\Models\Model;
- use Prettus\Repository\Contracts\Transformable;
- use Prettus\Repository\Traits\TransformableTrait;
- /**
- * Class Category.
- *
- * @package namespace App\Repositories\Models\Inform;
- */
- class Category extends Model implements Transformable
- {
- use TransformableTrait;
- protected $table = 'inform_categories';
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $guarded = [];
- protected static function booted()
- {
- self::language();
- }
- public function getParentNameAttribute()
- {
- return self::query()->where('id', $this->attributes['parent_id'])->value('name') ?? '--';
- }
- public function setRoleIdsAttribute($val)
- {
- $this->attributes['role_ids'] = '-' . arr2str0($val, '-') . '-';
- }
- public function getRoleIdsAttribute($val)
- {
- return str2arr0(trim($val, '-'), '-');
- }
- public static function sonGroup($id)
- {
- $str = [];
- $num = self::query()->where('parent_id', '=', $id)->pluck('id')->toArray();
- if (count($num)) {
- foreach ($num as $k => $v) {
- $str[] = $v;
- $ids = self::sonGroup($v);
- foreach ($ids as $i) {
- $str[] = $i;
- }
- }
- }
- return $str;
- }
- public static function byRoleGetIds($role_id)
- {
- if (login_admin_id() == 1) {
- return self::query()->pluck('id')->toArray();
- }
- return self::query()->where('role_ids', 'like', "%-{$role_id}-%")->orWhere('role_ids', 'like', "%-0-%")->pluck('id')->toArray();
- }
- }
|