1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace App\Models\Coach;
- use App\Models\Service\Project;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Notifications\Notifiable;
- use Illuminate\Support\Facades\DB;
- class User extends Model
- {
- use HasFactory, Notifiable;
- protected $table = 'coach_users';
- /**
- * The attributes that are mass assignable.
- *
- * @var array<int, string>
- */
- protected $fillable = [];
- protected $guarded = [];
- protected $appends = [];
- /**
- * The attributes that should be hidden for serialization.
- *
- * @var array<int, string>
- */
- protected $hidden = [];
- /**
- * Get the attributes that should be cast.
- *
- * @return array<string, string>
- */
- protected function casts(): array
- {
- return [
- // 'password' => 'hashed',
- 'verify_time' => 'datetime',
- 'auth_time' => 'datetime'
- ];
- }
- public function getVerifyStatusAttribute()
- {
- return '1232';
- }
- public function info($attribute, $file = ['*']): array
- {
- (gettype($attribute) === "string" || gettype($attribute) === "integer") && ($attribute = ['id' => $attribute]);
- if (gettype($attribute) === "NULL") return [];
- $data = $this::query()->where($attribute)->first($file);
- return !empty($data) ? $data->toArray() : [];
- }
- public function getProject($category_id, $is_add = 0)
- {
- $project_ids = DB::table('service_project_has_category')->where('category_id', $category_id)->pluck('project_id');
- $project_ids = DB::table('service_project_has_coach')->whereIn('project_id', $project_ids)->where('coach_id', $this->attributes['id'])->where('status', 1)->pluck('project_id');
- $select = ['id', 'title', 'sub_title as subTitle', 'cover', 'price', 'init_price as initPrice', 'total_sale as totalSale', 'time_long as timeLong'];
- return Project::query()->whereIn('id', $project_ids)->where('status', 0)->where('is_add', $is_add)->select($select)->orderByDesc('sort')->get();
- }
- public function verify()
- {
- return $this->hasOne(Verify::class, 'coach_id');
- }
- public function member(): \Illuminate\Database\Eloquent\Relations\HasOne
- {
- return $this->hasOne(\App\Models\Member\User::class, 'id', 'user_id');
- }
- public function site(): \Illuminate\Database\Eloquent\Relations\HasOne
- {
- return $this->hasOne(Site::class, 'coach_id', 'id');
- }
- }
|