FEATURE: make adding custom fields working

This commit is contained in:
Michal Kváček
2016-01-26 22:44:15 +01:00
parent fedb5abae6
commit 271f27be0b
5 changed files with 77 additions and 28 deletions
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Enumerations\CustomFieldTypes;
use App\Http\Requests\NewCustomFieldRequest;
use App\Models\CustomField;
class CreateNewCustomField extends Controller
{
@@ -16,5 +17,41 @@ class CreateNewCustomField extends Controller
public function postNew(NewCustomFieldRequest $request)
{
$customField = new CustomField();
// @todo add support for determination of resource for custom field (module, user, ...)
// @todo add possible values
$customField->name = $request->name;
$customField->type_id = $request->type;
$customField->required = $request->has('required');
// set non-mandatory fields
if ($request->description) {
$customField->description = $request->description;
}
if ($request->defaultValue) {
$customField->default_value = $request->defaultValue;
}
if ($request->regExp) {
$customField->regexp = $request->regExp;
}
if ($request->minLength) {
$customField->min_length = $request->minLength;
}
if ($request->maxLength) {
$customField->max_length = $request->maxLength;
}
$customField->save();
return redirect()
->route('customfields.new')
->with('success', trans('admin/customFields.successfullyCreated'));
}
}
+2 -2
View File
@@ -13,9 +13,9 @@ class NewCustomFieldRequest extends Request
{
return [
'name' => 'required',
'type' => 'required|exists:custom_field_types',
'type' => 'required|exists:custom_field_types,id',
'minLength' => 'numeric|min:0',
'maxLength' => 'numeric|mix:0'
'maxLength' => 'numeric|min:0',
];
}
}