Fix PIREP submission and field slug problems on PIREP edit
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
35
app/Models/Observers/Sluggable.php
Normal file
35
app/Models/Observers/Sluggable.php
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
];
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user