Backend changes separating id from pilot_id
This commit is contained in:
26
app/Models/Observers/UserObserver.php
Normal file
26
app/Models/Observers/UserObserver.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Observers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\UserService;
|
||||
|
||||
class UserObserver
|
||||
{
|
||||
private $userSvc;
|
||||
|
||||
public function __construct(UserService $userSvc)
|
||||
{
|
||||
$this->userSvc = $userSvc;
|
||||
}
|
||||
|
||||
/**
|
||||
* After a user has been created, do some stuff
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function created(User $user): void
|
||||
{
|
||||
$this->userSvc->findAndSetPilotId($user);
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,17 @@ use Illuminate\Notifications\Notifiable;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
|
||||
/**
|
||||
* @property int id
|
||||
* @property int id
|
||||
* @property int pilot_id
|
||||
* @property string name
|
||||
* @property string email
|
||||
* @property string password
|
||||
* @property string api_key
|
||||
* @property mixed ident
|
||||
* @property mixed timezone
|
||||
* @property string ident
|
||||
* @property string curr_airport_id
|
||||
* @property string home_airport_id
|
||||
* @property Airline airline
|
||||
* @property Flight[] flights
|
||||
* @property string flight_time
|
||||
* @property string remember_token
|
||||
@@ -45,9 +48,11 @@ class User extends Authenticatable
|
||||
public $journal_type = JournalType::USER;
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'pilot_id',
|
||||
'airline_id',
|
||||
'rank_id',
|
||||
'api_key',
|
||||
@@ -78,6 +83,8 @@ class User extends Authenticatable
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'pilot_id' => 'integer',
|
||||
'flights' => 'integer',
|
||||
'flight_time' => 'integer',
|
||||
'transfer_time' => 'integer',
|
||||
@@ -96,19 +103,11 @@ class User extends Authenticatable
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPilotIdAttribute()
|
||||
public function getIdentAttribute()
|
||||
{
|
||||
$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 $this->airline->icao . str_pad($this->pilot_id, $length, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user