Set slug properly on pirep field and fix validation
This commit is contained in:
parent
282421deb8
commit
995d53df3e
@ -53,10 +53,11 @@ class PirepFieldController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function store(CreatePirepFieldRequest $request)
|
public function store(CreatePirepFieldRequest $request)
|
||||||
{
|
{
|
||||||
$input = $request->all();
|
$attrs = $request->all();
|
||||||
$input['required'] = get_truth_state($input['required']);
|
$attrs['slug'] = str_slug($attrs['name']);
|
||||||
|
$attrs['required'] = get_truth_state($attrs['required']);
|
||||||
|
|
||||||
$this->pirepFieldRepo->create($input);
|
$this->pirepFieldRepo->create($attrs);
|
||||||
|
|
||||||
Flash::success('PirepField saved successfully.');
|
Flash::success('PirepField saved successfully.');
|
||||||
return redirect(route('admin.pirepfields.index'));
|
return redirect(route('admin.pirepfields.index'));
|
||||||
@ -114,6 +115,7 @@ class PirepFieldController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$attrs = $request->all();
|
$attrs = $request->all();
|
||||||
|
$attrs['slug'] = str_slug($attrs['name']);
|
||||||
$attrs['required'] = get_truth_state($attrs['required']);
|
$attrs['required'] = get_truth_state($attrs['required']);
|
||||||
$this->pirepFieldRepo->update($attrs, $id);
|
$this->pirepFieldRepo->update($attrs, $id);
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ class PirepController extends Controller
|
|||||||
public function store(CreatePirepRequest $request)
|
public function store(CreatePirepRequest $request)
|
||||||
{
|
{
|
||||||
// Create the main PIREP
|
// Create the main PIREP
|
||||||
$pirep = new Pirep($request->all());
|
$pirep = new Pirep($request->post());
|
||||||
$pirep->user_id = Auth::user()->id;
|
$pirep->user_id = Auth::user()->id;
|
||||||
|
|
||||||
# Make sure this isn't a duplicate
|
# Make sure this isn't a duplicate
|
||||||
@ -140,8 +140,9 @@ class PirepController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Any special fields
|
// Any special fields
|
||||||
$pirep->flight_time = ((int) Utils::hoursToMinutes($request['hours']))
|
$hours = (int) $request->input('hours', 0);
|
||||||
+ ((int) $request['minutes']);
|
$minutes = (int) $request->input('minutes', 0);
|
||||||
|
$pirep->flight_time = Utils::hoursToMinutes($hours) + $minutes;
|
||||||
|
|
||||||
// The custom fields from the form
|
// The custom fields from the form
|
||||||
$custom_fields = [];
|
$custom_fields = [];
|
||||||
|
@ -30,13 +30,14 @@ class CreatePirepRequest extends FormRequest
|
|||||||
$field_rules = Pirep::$rules;
|
$field_rules = Pirep::$rules;
|
||||||
|
|
||||||
$field_rules['hours'] = 'nullable|integer';
|
$field_rules['hours'] = 'nullable|integer';
|
||||||
$field_rules['minutes'] = 'required|integer';
|
$field_rules['minutes'] = 'nullable|integer';
|
||||||
|
|
||||||
# Add the validation rules for the custom fields
|
# Add the validation rules for the custom fields
|
||||||
$pirepFieldRepo = app(PirepFieldRepository::class);
|
$pirepFieldRepo = app(PirepFieldRepository::class);
|
||||||
|
|
||||||
$custom_fields = $pirepFieldRepo->all();
|
$custom_fields = $pirepFieldRepo->all();
|
||||||
foreach ($custom_fields as $field) {
|
foreach ($custom_fields as $field) {
|
||||||
|
Log::info('field:', $field->toArray());
|
||||||
$field_rules[$field->slug] = $field->required ? 'required' : 'nullable';
|
$field_rules[$field->slug] = $field->required ? 'required' : 'nullable';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class PirepField
|
* Class PirepField
|
||||||
*
|
*
|
||||||
@ -37,18 +39,14 @@ class PirepField extends BaseModel
|
|||||||
* On creation
|
* On creation
|
||||||
*/
|
*/
|
||||||
static::creating(function (PirepField $model) {
|
static::creating(function (PirepField $model) {
|
||||||
if (!empty($model->slug)) {
|
|
||||||
$model->slug = str_slug($model->name);
|
$model->slug = str_slug($model->name);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When updating
|
* When updating
|
||||||
*/
|
*/
|
||||||
static::updating(function(PirepField $model) {
|
static::updating(function(PirepField $model) {
|
||||||
if (!empty($model->slug)) {
|
|
||||||
$model->slug = str_slug($model->name);
|
$model->slug = str_slug($model->name);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user