Fix PIREP submission and field slug problems on PIREP edit

This commit is contained in:
Nabeel Shahzad
2018-05-30 14:00:20 -05:00
parent b7a6cb4fbc
commit a083f9c671
13 changed files with 102 additions and 47 deletions

View File

@@ -18,11 +18,21 @@ class FlightFieldValue extends Model
protected $fillable = [
'flight_id',
'name',
'slug',
'value',
];
public static $rules = [];
/**
* @param $name
*/
public function setNameAttribute($name): void
{
$this->attributes['name'] = $name;
$this->attributes['slug'] = str_slug($name);
}
/**
* Relationships
*/

View File

@@ -1,28 +0,0 @@
<?php
namespace App\Models\Observers;
use App\Models\PirepField;
/**
* Class PirepFieldObserver
* @package App\Models\Observers
*/
class PirepFieldObserver
{
/**
* @param PirepField $model
*/
public function creating(PirepField $model): void
{
$model->slug = str_slug($model->name);
}
/**
* @param PirepField $model
*/
public function updating(PirepField $model): void
{
$model->slug = str_slug($model->name);
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Models\Observers;
/**
* Create a slug from a name
* @package App\Models\Observers
*/
class Sluggable
{
/**
* @param $model
*/
public function creating($model): void
{
$model->slug = str_slug($model->name);
}
/**
* @param $model
*/
public function updating($model): void
{
$model->slug = str_slug($model->name);
}
/**
* @param $name
*/
public function setNameAttribute($name): void
{
$this->attributes['name'] = $name;
$this->attributes['slug'] = str_slug($name);
}
}

View File

@@ -45,6 +45,7 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName;
* @property Carbon submitted_at
* @property Carbon created_at
* @property Carbon updated_at
* @property bool read_only
* @property Acars position
* @property Acars[] acars
* @package App\Models
@@ -127,9 +128,9 @@ class Pirep extends Model
* If a PIREP is in these states, then it can't be changed.
*/
public static $read_only_states = [
PirepState::PENDING,
PirepState::ACCEPTED,
PirepState::REJECTED,
//PirepState::PENDING,
PirepState::CANCELLED,
];

View File

@@ -15,6 +15,7 @@ class PirepFieldValues extends Model
protected $fillable = [
'pirep_id',
'name',
'slug',
'value',
'source',
];
@@ -23,6 +24,15 @@ class PirepFieldValues extends Model
'name' => 'required',
];
/**
* @param $name
*/
public function setNameAttribute($name): void
{
$this->attributes['name'] = $name;
$this->attributes['slug'] = str_slug($name);
}
/**
* Foreign Keys
*/