Skip to content

Commit

Permalink
update to handle view, create and edit field types on resource
Browse files Browse the repository at this point in the history
  • Loading branch information
philmareu committed Jul 30, 2018
1 parent a0e38ae commit 0eeefc3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
19 changes: 19 additions & 0 deletions src/PhilMareu/Laramanager/FieldTypes/TextFieldType.php
Expand Up @@ -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)
{

}
}
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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,
]);
}

Expand All @@ -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');
Expand Down
Expand Up @@ -9,7 +9,6 @@ class LaramanagerResourceField extends Model {
protected $fillable = [
'title',
'slug',
'type',
'validation',
'is_required',
'is_unique',
Expand Down
2 changes: 1 addition & 1 deletion src/views/resources/fields/create.blade.php
Expand Up @@ -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">

Expand Down
3 changes: 1 addition & 2 deletions src/views/resources/fields/edit.blade.php
Expand Up @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion src/views/resources/fields/index.blade.php
Expand Up @@ -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">
Expand Down

0 comments on commit 0eeefc3

Please sign in to comment.