phpvms/app/Models/User.php

136 lines
3.1 KiB
PHP
Raw Normal View History

2017-06-09 02:28:26 +08:00
<?php
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;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Contracts\Auth\CanResetPassword;
2017-06-09 02:28:26 +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;
//use SoftDeletes;
2017-06-09 02:28:26 +08:00
public $table = 'users';
protected $fillable = [
'name',
'email',
'password',
'airline_id',
2017-12-31 02:15:26 +08:00
'api_key',
'home_airport_id',
'curr_airport_id',
'last_pirep_id',
'rank_id',
'timezone',
'state',
'status',
];
2017-06-09 02:28:26 +08:00
/**
* 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',
];
2017-06-29 08:56:10 +08:00
public static $rules = [
2018-01-01 03:08:41 +08:00
'name' => 'required',
'email' => 'required|email|unique:users,email',
];
2018-01-01 03:08:41 +08:00
/**
* @return string
*/
public function getPilotIdAttribute()
2017-07-03 10:25:48 +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()
{
$size = 80;
$default = 'https://en.gravatar.com/userimage/12856995/7c7c1da6387853fea65ff74983055386.png';
2018-01-01 03:08:41 +08:00
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');
}
public function last_pirep()
{
return $this->belongsTo('App\Models\Pirep', 'last_pirep_id');
}
public function bids()
2017-08-04 10:02:02 +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
}