2017-06-09 02:28:26 +08:00
|
|
|
<?php
|
|
|
|
|
2017-06-11 09:10:31 +08:00
|
|
|
namespace App\Models;
|
2017-06-09 02:28:26 +08:00
|
|
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
2017-12-16 02:36:13 +08:00
|
|
|
use Laratrust\Traits\LaratrustUserTrait;
|
2017-06-22 00:40:08 +08:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2017-06-22 18:23:59 +08:00
|
|
|
use Illuminate\Contracts\Auth\CanResetPassword;
|
2017-06-09 02:28:26 +08:00
|
|
|
|
|
|
|
/**
|
2017-12-13 06:58:27 +08:00
|
|
|
* @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
|
2017-12-16 02:36:13 +08:00
|
|
|
* @mixin \Laratrust\Traits\LaratrustUserTrait
|
2017-06-09 02:28:26 +08:00
|
|
|
*/
|
|
|
|
class User extends Authenticatable
|
|
|
|
{
|
|
|
|
use Notifiable;
|
2017-12-16 02:36:13 +08:00
|
|
|
use LaratrustUserTrait;
|
2017-12-13 06:58:27 +08:00
|
|
|
//use SoftDeletes;
|
2017-06-09 02:28:26 +08:00
|
|
|
|
2017-12-13 06:58:27 +08:00
|
|
|
public $table = 'users';
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
'email',
|
|
|
|
'password',
|
|
|
|
'airline_id',
|
2018-01-04 05:41:21 +08:00
|
|
|
'rank_id',
|
2017-12-31 02:15:26 +08:00
|
|
|
'api_key',
|
2017-12-13 06:58:27 +08:00
|
|
|
'home_airport_id',
|
|
|
|
'curr_airport_id',
|
2017-12-26 05:19:34 +08:00
|
|
|
'last_pirep_id',
|
2018-01-04 05:41:21 +08:00
|
|
|
'flights',
|
|
|
|
'flight_time',
|
|
|
|
'balance',
|
2017-12-13 06:58:27 +08:00
|
|
|
'timezone',
|
2017-12-23 02:46:46 +08:00
|
|
|
'state',
|
|
|
|
'status',
|
2017-12-13 06:58:27 +08:00
|
|
|
];
|
2017-06-09 02:28:26 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*/
|
2017-12-13 02:43:58 +08:00
|
|
|
protected $hidden = [
|
|
|
|
'password',
|
|
|
|
'remember_token',
|
|
|
|
];
|
2017-07-04 14:05:37 +08:00
|
|
|
|
2017-12-13 02:43:58 +08:00
|
|
|
protected $casts = [
|
|
|
|
'flights' => 'integer',
|
|
|
|
'flight_time' => 'integer',
|
|
|
|
'balance' => 'double',
|
2017-12-23 22:36:02 +08:00
|
|
|
'state' => 'integer',
|
|
|
|
'status' => 'integer',
|
2017-12-13 02:43:58 +08:00
|
|
|
];
|
2017-06-29 08:56:10 +08:00
|
|
|
|
2017-12-23 06:32:21 +08:00
|
|
|
public static $rules = [
|
2018-01-01 03:08:41 +08:00
|
|
|
'name' => 'required',
|
2018-01-03 13:15:48 +08:00
|
|
|
'email' => 'required|email',
|
2017-12-23 06:32:21 +08:00
|
|
|
];
|
|
|
|
|
2018-01-01 03:08:41 +08:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPilotIdAttribute()
|
2017-07-03 10:25:48 +08:00
|
|
|
{
|
2017-12-13 02:43:58 +08:00
|
|
|
$length = setting('pilots.id_length');
|
|
|
|
return $this->airline->icao . str_pad($this->id, $length, '0', STR_PAD_LEFT);
|
2017-07-03 10:25:48 +08:00
|
|
|
}
|
|
|
|
|
2018-01-01 03:08:41 +08:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getIdentAttribute()
|
|
|
|
{
|
|
|
|
return $this->getPilotIdAttribute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getGravatarAttribute()
|
2017-08-12 01:06:17 +08:00
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
$size = config('gravatar.size');
|
|
|
|
$default = config('gravatar.default');
|
|
|
|
return config('gravatar.url') .
|
2018-01-01 03:08:41 +08:00
|
|
|
md5(strtolower(trim($this->email))) . '?d=' . urlencode($default ) . '&s=' . $size;
|
2017-08-12 01:06:17 +08:00
|
|
|
}
|
|
|
|
|
2017-06-29 08:56:10 +08:00
|
|
|
/**
|
|
|
|
* Foreign Keys
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function airline()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsTo(Airline::class, 'airline_id');
|
2017-06-29 08:56:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function home_airport()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsTo(Airport::class, 'home_airport_id');
|
2017-06-29 08:56:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function current_airport()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsTo(Airport::class, 'curr_airport_id');
|
2017-06-29 08:56:10 +08:00
|
|
|
}
|
|
|
|
|
2017-12-26 05:19:34 +08:00
|
|
|
public function last_pirep()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsTo(Pirep::class, 'last_pirep_id');
|
2017-12-26 05:19:34 +08:00
|
|
|
}
|
|
|
|
|
2017-12-13 06:58:27 +08:00
|
|
|
public function bids()
|
2017-08-04 10:02:02 +08:00
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->hasMany(UserBid::class, 'user_id');
|
2017-08-04 10:02:02 +08:00
|
|
|
}
|
|
|
|
|
2017-06-30 04:50:16 +08:00
|
|
|
public function pireps()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->hasMany(Pirep::class, 'user_id');
|
2017-06-30 04:50:16 +08:00
|
|
|
}
|
|
|
|
|
2017-06-29 08:56:10 +08:00
|
|
|
public function rank()
|
|
|
|
{
|
2018-01-08 23:22:12 +08:00
|
|
|
return $this->belongsTo(Rank::class, 'rank_id');
|
2017-06-29 08:56:10 +08:00
|
|
|
}
|
2017-06-09 02:28:26 +08:00
|
|
|
}
|