140 lines
3.1 KiB
PHP
Executable File
140 lines
3.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Laratrust\Traits\LaratrustUserTrait;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Contracts\Auth\CanResetPassword;
|
|
|
|
/**
|
|
* @property integer $id
|
|
* @property string $name
|
|
* @property string $email
|
|
* @property string $password
|
|
* @property string $api_key
|
|
* @property string $flights
|
|
* @property string $flight_time
|
|
* @property string $remember_token
|
|
* @property \Carbon\Carbon $created_at
|
|
* @property \Carbon\Carbon $updated_at
|
|
* @mixin \Illuminate\Notifications\Notifiable
|
|
* @mixin \Laratrust\Traits\LaratrustUserTrait
|
|
*/
|
|
class User extends Authenticatable
|
|
{
|
|
use Notifiable;
|
|
use LaratrustUserTrait;
|
|
//use SoftDeletes;
|
|
|
|
public $table = 'users';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'airline_id',
|
|
'rank_id',
|
|
'api_key',
|
|
'country',
|
|
'home_airport_id',
|
|
'curr_airport_id',
|
|
'last_pirep_id',
|
|
'flights',
|
|
'flight_time',
|
|
'balance',
|
|
'timezone',
|
|
'state',
|
|
'status',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
protected $casts = [
|
|
'flights' => 'integer',
|
|
'flight_time' => 'integer',
|
|
'balance' => 'double',
|
|
'state' => 'integer',
|
|
'status' => 'integer',
|
|
];
|
|
|
|
public static $rules = [
|
|
'name' => 'required',
|
|
'email' => 'required|email',
|
|
];
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getPilotIdAttribute()
|
|
{
|
|
$length = setting('pilots.id_length');
|
|
return $this->airline->icao . str_pad($this->id, $length, '0', STR_PAD_LEFT);
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getIdentAttribute()
|
|
{
|
|
return $this->getPilotIdAttribute();
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getGravatarAttribute()
|
|
{
|
|
$size = config('gravatar.size');
|
|
$default = config('gravatar.default');
|
|
return config('gravatar.url') .
|
|
md5(strtolower(trim($this->email))) . '?d=' . urlencode($default ) . '&s=' . $size;
|
|
}
|
|
|
|
/**
|
|
* Foreign Keys
|
|
*/
|
|
|
|
public function airline()
|
|
{
|
|
return $this->belongsTo(Airline::class, 'airline_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 bids()
|
|
{
|
|
return $this->hasMany(UserBid::class, 'user_id');
|
|
}
|
|
|
|
public function pireps()
|
|
{
|
|
return $this->hasMany(Pirep::class, 'user_id');
|
|
}
|
|
|
|
public function rank()
|
|
{
|
|
return $this->belongsTo(Rank::class, 'rank_id');
|
|
}
|
|
}
|