123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Repositories\Models\Course;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Models\Base\Resource;
- use App\Repositories\Models\Model;
- use App\Repositories\Models\User\User;
- use Prettus\Repository\Contracts\Transformable;
- use Prettus\Repository\Traits\TransformableTrait;
- /**
- * Class Organization.
- *
- * @package namespace App\Repositories\Models\Course;
- */
- class Organization extends Model implements Transformable
- {
- use TransformableTrait;
- protected $table = 'course_organizations';
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $guarded = [];
- public function cover_resource()
- {
- return $this->belongsTo(Resource::class, 'cover', 'id')->select(['path', 'id', 'url']);
- }
- public function coordinator()
- {
- return $this->belongsTo(User::class)->select(['id', 'name', 'mobile', 'headimg', 'turename', 'userrate', 'personal_signature']);
- }
- public function user()
- {
- return $this->belongsTo(User::class)->select(['id', 'name', 'mobile', 'turename']);
- }
- public function courses()
- {
- return $this->belongsToMany(Course::class, 'course_organization_course')->withTimestamps();
- }
- public function students()
- {
- return $this->belongsToMany(User::class, 'course_organization_student')->withTimestamps();
- }
- public function setTagsAttribute($val)
- {
- $this->attributes['tags'] = '-' . arr2str($val, '-') . '-';
- }
- public function getTagsAttribute($val)
- {
- return str2arr(trim($val, '-'), '-');
- }
- public function student()
- {
- return $this->hasMany(OrganizationStudent::class);
- }
- public function getIsMemberStatusAttribute()
- {
- return OrganizationStudent::query()->where('organization_id', $this->attributes['id'])->where('user_id', login_user_id())->where('status', ModelStatusEnum::OK)->exists();
- }
- }
|