Permalink
Browse files

update to handle view, create and edit field types on resource

  • Loading branch information...
philmareu committed Jul 30, 2018
1 parent a0e38ae commit 0eeefc3ccd2b4633e72d4dee59b309ce44ae44df
@@ -3,7 +3,26 @@
namespace PhilMareu\Laramanager\FieldTypes;
use Illuminate\Http\Request;
class TextFieldType
{
protected $viewDirectory = 'laramanager::field_types.text';
protected $slug = 'text';
public function getViewDirectory()
{
return $this->viewDirectory;
}
public function mutate(Request $request)
{
}
public function relationships($entry)
{
}
}
@@ -61,13 +61,17 @@ public function store(Request $request, $resourceId)
'validation' => 'required',
'is_unique' => 'boolean',
'is_required' => 'boolean',
'type' => 'required|not_in:0',
'field_type_id' => 'required|in:' . $this->fieldTypes->implode('id', ','),
'data' => 'array'
]);
$attributes = $this->serializeData($request);
$resource->fields()->create($attributes);
$resource = $resource->fields()->make($attributes);
$resource->fieldType()->associate(
$this->fieldTypes->where('id', $request->field_type_id)->first()
);
$resource->save();
return redirect('admin/resources/' . $resourceId . '/fields')->with('success', 'Field added');
}
@@ -96,8 +100,8 @@ public function edit($resourceId, $fieldId)
return view('laramanager::resources.fields.edit', [
'resource' => $resource,
'fields' => $this->fieldTypes,
'field' => $field
'fieldTypes' => $this->fieldTypes,
'field' => $field,
]);
}
@@ -118,14 +122,19 @@ public function update(Request $request, $resourceId, $fieldId)
'validation' => '',
'is_unique' => 'boolean',
'is_required' => 'boolean',
'type' => 'required|not_in:0',
'field_type_id' => 'required|in:' . $this->fieldTypes->implode('id', ','),
'data' => 'array'
]);
$attributes = $this->serializeData($request);
$attributes['is_unique'] = $request->has('is_unique') ? 1 : 0;
$attributes['list'] = $request->has('list') ? 1 : 0;
$field->fieldType()->associate(
$this->fieldTypes->where('id', $request->field_type_id)->first()
);
$field->save();
$field->update($attributes);
return redirect('admin/resources/' . $resourceId . '/fields/' . $field->id . '/edit')->with('success', 'Field updated');
@@ -9,7 +9,6 @@ class LaramanagerResourceField extends Model {
protected $fillable = [
'title',
'slug',
'type',
'validation',
'is_required',
'is_unique',
@@ -28,7 +28,7 @@
@include('laramanager::partials.elements.form.slug', ['field' => ['name' => 'validation']])
@include('laramanager::partials.elements.form.checkbox', ['field' => ['name' => 'is_unique', 'checked' => false]])
@include('laramanager::partials.elements.form.checkbox', ['field' => ['name' => 'list', 'checked' => false]])
@include('laramanager::partials.elements.form.select', ['field' => ['name' => 'type', 'options' => $fieldTypes->pluck('title', 'id'), 'id' => 'type']])
@include('laramanager::partials.elements.form.select', ['field' => ['name' => 'field_type_id', 'options' => $fieldTypes->pluck('title', 'id'), 'id' => 'type']])
<div id="options" class="uk-form-row">
@@ -30,8 +30,7 @@
@include('laramanager::partials.elements.form.slug', ['field' => ['name' => 'validation', 'value' => $field->validation]])
@include('laramanager::partials.elements.form.checkbox', ['field' => ['name' => 'is_unique', 'checked' => $field->is_unique]])
@include('laramanager::partials.elements.form.checkbox', ['field' => ['name' => 'list', 'checked' => $field->list]])
@include('laramanager::partials.elements.form.select', ['field' => ['name' => 'type', 'options' => $fields, 'id' => 'type', 'value' => $field->type]])
@include('laramanager::partials.elements.form.select', ['field' => ['name' => 'field_type_id', 'options' => $fieldTypes->pluck('title', 'id'), 'id' => 'type', 'value' => $field->fieldType->id]])
<div id="options" class="uk-form-row">
@if(view()->exists('laramanager::fields.' . $field->type . '.options'))
@@ -27,7 +27,7 @@
<tr>
<td>{{ $field->title }}</td>
<td>{{ $field->slug }}</td>
<td>{{ $field->type }}</td>
<td>{{ $field->fieldType->title }}</td>
<td width="50">
<div class="uk-grid uk-grid-medium">

0 comments on commit 0eeefc3

Please sign in to comment.