'integer', 'pilot_id' => 'integer', 'flights' => 'integer', 'flight_time' => 'integer', 'transfer_time' => 'integer', 'balance' => 'double', 'state' => 'integer', 'status' => 'integer', 'toc_accepted' => 'boolean', 'opt_in' => 'boolean', ]; public static $rules = [ 'name' => 'required', 'email' => 'required|email', 'pilot_id' => 'required|integer', ]; /** * @return string */ public function getIdentAttribute(): string { $length = setting('pilots.id_length'); return optional($this->airline)->icao.str_pad($this->pilot_id, $length, '0', STR_PAD_LEFT); } /** * Return a "privatized" version of someones name - First name full, rest of the names are initials * * @return string */ public function getNamePrivateAttribute(): string { $name_parts = explode(' ', $this->attributes['name']); $count = count($name_parts); if ($count === 1) { return $name_parts[0]; } $first_name = $name_parts[0]; $last_name = $name_parts[$count - 1]; return $first_name.' '.$last_name[0]; } /** * Shorthand for getting the timezone * * @return string */ public function getTzAttribute(): string { return $this->timezone; } /** * Shorthand for setting the timezone * * @param $value */ public function setTzAttribute($value) { $this->attributes['timezone'] = $value; } /** * Return a File model */ public function getAvatarAttribute() { if (!$this->attributes['avatar']) { return null; } return new File([ 'path' => $this->attributes['avatar'], ]); } /** * @param mixed $size Size of the gravatar, in pixels * * @return string */ public function gravatar($size = null) { $default = config('gravatar.default'); $uri = config('gravatar.url').md5(strtolower(trim($this->email))).'?d='.urlencode($default); if ($size !== null) { $uri .= '&s='.$size; } return $uri; } public function resolveAvatarUrl() { $avatar = $this->getAvatarAttribute(); if (empty($avatar)) { return $this->gravatar(); } return $avatar->url; } /** * Foreign Keys */ public function airline() { return $this->belongsTo(Airline::class, 'airline_id'); } /** * @return \App\Models\Award[]|mixed */ public function awards() { return $this->belongsToMany(Award::class, 'user_awards'); } /** * The bid rows * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function bids() { return $this->hasMany(Bid::class, 'user_id'); } public function home_airport() { return $this->belongsTo(Airport::class, 'home_airport_id'); } public function current_airport() { return $this->belongsTo(Airport::class, 'curr_airport_id'); } public function last_pirep() { return $this->belongsTo(Pirep::class, 'last_pirep_id'); } public function fields() { return $this->hasMany(UserFieldValue::class, 'user_id'); } public function pireps() { return $this->hasMany(Pirep::class, 'user_id'); } public function rank() { return $this->belongsTo(Rank::class, 'rank_id'); } public function typeratings() { return $this->belongsToMany(Typerating::class, 'typerating_user', 'user_id', 'typerating_id'); } public function rated_subfleets() { return $this->hasManyDeep(Subfleet::class, ['typerating_user', Typerating::class, 'typerating_subfleet']); } }