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-06-11 09:10:31 +08:00
|
|
|
use Zizaco\Entrust\Traits\EntrustUserTrait;
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* App\User
|
|
|
|
*
|
2017-07-04 14:05:37 +08:00
|
|
|
* @property integer
|
|
|
|
* $id
|
|
|
|
* @property string
|
|
|
|
* $name
|
|
|
|
* @property string
|
|
|
|
* $email
|
|
|
|
* @property string
|
|
|
|
* $password
|
|
|
|
* @property string
|
|
|
|
* $remember_token
|
|
|
|
* @property \Carbon\Carbon
|
|
|
|
* $created_at
|
|
|
|
* @property \Carbon\Carbon
|
|
|
|
* $updated_at
|
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[]
|
|
|
|
* $notifications
|
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[]
|
|
|
|
* $unreadNotifications
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\User
|
|
|
|
* whereId($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\User
|
|
|
|
* whereName($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\User
|
|
|
|
* whereEmail($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\User
|
|
|
|
* wherePassword($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\User
|
|
|
|
* whereRememberToken($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\User
|
|
|
|
* whereCreatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\User
|
|
|
|
* whereUpdatedAt($value)
|
2017-06-09 02:28:26 +08:00
|
|
|
* @mixin \Eloquent
|
|
|
|
*/
|
|
|
|
class User extends Authenticatable
|
|
|
|
{
|
|
|
|
use Notifiable;
|
2017-06-11 09:10:31 +08:00
|
|
|
use EntrustUserTrait;
|
2017-06-09 02:28:26 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-07-04 14:05:37 +08:00
|
|
|
protected $fillable
|
|
|
|
= [
|
|
|
|
'name',
|
|
|
|
'email',
|
|
|
|
'password',
|
2017-08-12 00:50:14 +08:00
|
|
|
'airline_id',
|
|
|
|
'home_airport_id',
|
|
|
|
'curr_airport_id',
|
2017-11-30 08:01:07 +08:00
|
|
|
'rank_id',
|
2017-12-07 06:07:25 +08:00
|
|
|
'timezone',
|
2017-11-30 08:01:07 +08:00
|
|
|
'active',
|
2017-07-04 14:05:37 +08:00
|
|
|
];
|
2017-06-09 02:28:26 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
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-06-29 08:56:10 +08:00
|
|
|
|
2017-11-30 08:01:07 +08:00
|
|
|
/**
|
|
|
|
* Validation rules
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public static $rules = [
|
|
|
|
|
|
|
|
];
|
|
|
|
|
2017-12-12 12:05:22 +08:00
|
|
|
/**
|
|
|
|
* Returns a 40 character API key that a user can use
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function generateApiKey()
|
|
|
|
{
|
|
|
|
$key = sha1(time() . mt_rand());
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
|
2017-12-13 02:43:58 +08:00
|
|
|
public function getPilotIdAttribute($value)
|
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
|
|
|
}
|
|
|
|
|
2017-08-12 01:06:17 +08:00
|
|
|
public function gravatar()
|
|
|
|
{
|
|
|
|
$size = 80;
|
|
|
|
$default = 'https://en.gravatar.com/userimage/12856995/7c7c1da6387853fea65ff74983055386.png';
|
|
|
|
return "https://www.gravatar.com/avatar/" .
|
|
|
|
md5( strtolower( trim( $this->email) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
|
|
|
|
}
|
|
|
|
|
2017-06-29 08:56:10 +08:00
|
|
|
/**
|
|
|
|
* Foreign Keys
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function airline()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\Airline', 'airline_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function home_airport()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\Airport', 'home_airport_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function current_airport()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\Airport', 'curr_airport_id');
|
|
|
|
}
|
|
|
|
|
2017-08-04 10:02:02 +08:00
|
|
|
public function flights()
|
|
|
|
{
|
2017-12-13 01:49:35 +08:00
|
|
|
return $this->hasMany('App\Models\UserBid', 'user_id');
|
2017-08-04 10:02:02 +08:00
|
|
|
}
|
|
|
|
|
2017-06-30 04:50:16 +08:00
|
|
|
public function pireps()
|
|
|
|
{
|
|
|
|
return $this->hasMany('App\Models\Pirep', 'user_id');
|
|
|
|
}
|
|
|
|
|
2017-06-29 08:56:10 +08:00
|
|
|
public function rank()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\Rank', 'rank_id');
|
|
|
|
}
|
2017-06-09 02:28:26 +08:00
|
|
|
}
|