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)
|
||||
{
|
||||
$input = $request->all();
|
||||
$input['required'] = get_truth_state($input['required']);
|
||||
$attrs = $request->all();
|
||||
$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.');
|
||||
return redirect(route('admin.pirepfields.index'));
|
||||
@ -114,6 +115,7 @@ class PirepFieldController extends BaseController
|
||||
}
|
||||
|
||||
$attrs = $request->all();
|
||||
$attrs['slug'] = str_slug($attrs['name']);
|
||||
$attrs['required'] = get_truth_state($attrs['required']);
|
||||
$this->pirepFieldRepo->update($attrs, $id);
|
||||
|
||||
|
@ -129,7 +129,7 @@ class PirepController extends Controller
|
||||
public function store(CreatePirepRequest $request)
|
||||
{
|
||||
// Create the main PIREP
|
||||
$pirep = new Pirep($request->all());
|
||||
$pirep = new Pirep($request->post());
|
||||
$pirep->user_id = Auth::user()->id;
|
||||
|
||||
# Make sure this isn't a duplicate
|
||||
@ -140,8 +140,9 @@ class PirepController extends Controller
|
||||
}
|
||||
|
||||
// Any special fields
|
||||
$pirep->flight_time = ((int) Utils::hoursToMinutes($request['hours']))
|
||||
+ ((int) $request['minutes']);
|
||||
$hours = (int) $request->input('hours', 0);
|
||||
$minutes = (int) $request->input('minutes', 0);
|
||||
$pirep->flight_time = Utils::hoursToMinutes($hours) + $minutes;
|
||||
|
||||
// The custom fields from the form
|
||||
$custom_fields = [];
|
||||
|
@ -30,13 +30,14 @@ class CreatePirepRequest extends FormRequest
|
||||
$field_rules = Pirep::$rules;
|
||||
|
||||
$field_rules['hours'] = 'nullable|integer';
|
||||
$field_rules['minutes'] = 'required|integer';
|
||||
$field_rules['minutes'] = 'nullable|integer';
|
||||
|
||||
# Add the validation rules for the custom fields
|
||||
$pirepFieldRepo = app(PirepFieldRepository::class);
|
||||
|
||||
$custom_fields = $pirepFieldRepo->all();
|
||||
foreach ($custom_fields as $field) {
|
||||
Log::info('field:', $field->toArray());
|
||||
$field_rules[$field->slug] = $field->required ? 'required' : 'nullable';
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class PirepField
|
||||
*
|
||||
@ -37,18 +39,14 @@ class PirepField extends BaseModel
|
||||
* On creation
|
||||
*/
|
||||
static::creating(function (PirepField $model) {
|
||||
if (!empty($model->slug)) {
|
||||
$model->slug = str_slug($model->name);
|
||||
}
|
||||
$model->slug = str_slug($model->name);
|
||||
});
|
||||
|
||||
/**
|
||||
* When updating
|
||||
*/
|
||||
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