Skip to content
Permalink
Browse files

added ability to populate a list of field types

  • Loading branch information...
philmareu committed Jul 23, 2018
1 parent b23bd47 commit bd173da63cb4ad79d98e11c32a687679be18f105
@@ -0,0 +1,56 @@
<?php
namespace PhilMareu\Laramanager\Http\Controllers;
use PhilMareu\Laramanager\Http\Requests\StoreFieldTypeRequest;
use PhilMareu\Laramanager\Http\Requests\UpdateFieldTypeRequest;
use PhilMareu\Laramanager\Models\LaramanagerFieldType;
class FieldTypesController extends Controller
{
protected $fieldType;
public function __construct(LaramanagerFieldType $fieldType)
{
$this->fieldType = $fieldType;
}
public function index()
{
$fieldTypes = $this->fieldType->all();
return view('laramanager::field_types.index')
->with('fieldTypes', $fieldTypes);
}
public function create()
{
return view('laramanager::field_types.create');
}
public function store(StoreFieldTypeRequest $request)
{
$request->offsetSet('active', $request->filled('active'));
$this->fieldType->create($request->all());
return redirect('admin/field-types');
}
public function edit($fieldTypeId)
{
$fieldType = $this->fieldType->findOrFail($fieldTypeId);
return view('laramanager::field_types.edit')
->with('fieldType', $fieldType);
}
public function update(UpdateFieldTypeRequest $request, $fieldTypeId)
{
$request->offsetSet('active', $request->filled('active'));
$fieldType = $this->fieldType->findOrFail($fieldTypeId);
$fieldType->update($request->all());
return redirect('admin/field-types');
}
}
@@ -0,0 +1,38 @@
<?php
/**
* Created by PhpStorm.
* User: philmareu
* Date: 7/23/18
* Time: 11:57 AM
*/
namespace PhilMareu\Laramanager\Http\Requests;
class StoreFieldTypeRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => 'required|max:255|unique:laramanager_field_types',
'slug' => 'required|max:255|unique:laramanager_field_types',
'class' => 'required|max:255|unique:laramanager_field_types',
'active' => 'boolean'
];
}
}
@@ -0,0 +1,40 @@
<?php
/**
* Created by PhpStorm.
* User: philmareu
* Date: 7/23/18
* Time: 11:59 AM
*/
namespace PhilMareu\Laramanager\Http\Requests;
use Illuminate\Validation\Rule;
class UpdateFieldTypeRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => 'required|max:255|' . Rule::unique('laramanager_field_types', 'title')->ignore($this->segment(3)),
'slug' => 'required|max:255|' . Rule::unique('laramanager_field_types', 'slug')->ignore($this->segment(3)),
'class' => 'required|max:255|' . Rule::unique('laramanager_field_types', 'class')->ignore($this->segment(3)),
'active' => 'boolean'
];
}
}
@@ -69,6 +69,7 @@
Route::resource('laramanager-navigation-sections', 'NavigationSectionsController');
Route::resource('laramanager-navigation-links', 'NavigationLinksController');
Route::resource('objects', 'ObjectsController');
Route::resource('field-types', 'FieldTypesController');
Route::resource('settings', 'SettingsController');
});
});
@@ -0,0 +1,16 @@
<?php
namespace PhilMareu\Laramanager\Models;
use Illuminate\Database\Eloquent\Model;
class LaramanagerFieldType extends Model
{
protected $fillable = [
'title',
'slug',
'class',
'active'
];
}
@@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateLaramanagerFieldTypesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('laramanager_field_types', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->string('slug');
$table->string('class');
$table->boolean('active');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('laramanager_field_types');
}
}
@@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use PhilMareu\Laramanager\Models\LaramanagerNavigationLink;
class CreateFieldTypesNavigationLink extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
LaramanagerNavigationLink::create([
'title' => 'Field Types',
'uri' => 'admin/field-types',
'ordinal' => 25,
'laramanager_navigation_section_id' => 4
]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
LaramanagerNavigationLink::where('title', 'Field Types')->delete();
}
}
@@ -0,0 +1,34 @@
@extends('laramanager::layouts.admin.default')

@section('title')
Create
@endsection

@section('breadcrumbs')
<li><a href="{{ route('admin.field-types.index') }}">Field Types</a></li>
<li><span>@yield('title')</span></li>
@endsection

@section('default-content')

<form action="{{ route('admin.field-types.store') }}" enctype="multipart/form-data" method="POST" class="uk-form uk-form-stacked">
<input type="hidden" name="_token" value="{{ csrf_token() }}">

@include('laramanager::partials.elements.form.text', ['field' => ['name' => 'title', 'id' => 'title']])
@include('laramanager::partials.elements.form.slug', ['field' => ['name' => 'slug', 'id' => 'slug', 'target' => 'title']])
@include('laramanager::partials.elements.form.text', ['field' => ['name' => 'class']])
@include('laramanager::partials.elements.form.checkbox', ['field' => ['name' => 'active', 'checked' => true]])

@include('laramanager::partials.elements.buttons.submit')

</form>

@endsection

@push('scripts-last')

<script>
$('#title').slugify({ slug: '#slug', type: '_' });
</script>

@endpush
@@ -0,0 +1,36 @@
@extends('laramanager::layouts.admin.default')

@section('title')
{{ $fieldType->title }}
@endsection

@section('breadcrumbs')
<li><a href="{{ route('admin.field-types.index') }}">Field Types</a></li>
<li class="uk-disabled"><a>Edit</a></li>
<li><span>@yield('title')</span></li>
@endsection

@section('default-content')

<form action="{{ route('admin.field-types.update', $fieldType->id) }}" enctype="multipart/form-data" method="POST" class="uk-form uk-form-stacked">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="_method" value="PUT">

@include('laramanager::partials.elements.form.text', ['field' => ['name' => 'title', 'id' => 'title', 'value' => $fieldType->title]])
@include('laramanager::partials.elements.form.slug', ['field' => ['name' => 'slug', 'id' => 'slug', 'target' => 'title', 'value' => $fieldType->slug]])
@include('laramanager::partials.elements.form.text', ['field' => ['name' => 'class', 'value' => $fieldType->class]])
@include('laramanager::partials.elements.form.checkbox', ['field' => ['name' => 'active', 'checked' => $fieldType->active]])

@include('laramanager::partials.elements.buttons.submit', ['submitText' => 'Update'])

</form>

@endsection

@push('scripts-last')

<script>
$('#title').slugify({ slug: '#slug', type: '_' });
</script>

@endpush
@@ -0,0 +1,52 @@
@extends('laramanager::layouts.admin.table')

@section('title')
Field Types
@endsection

@section('breadcrumbs')
<li><span>@yield('title')</span></li>
@endsection

@section('actions')
<a href="{{ route('admin.field-types.create') }}" class="uk-button uk-button-primary uk-button-small">Create</a>
@endsection

@section('table-headers')
<td>Title</td>
<td>Slug</td>
<td>Class</td>
<td>Active</td>
<td>&nbsp;</td>
@endsection

@section('table-body')
@foreach($fieldTypes as $fieldType)
<tr>
<td>{{ $fieldType->title }}</td>
<td>{{ $fieldType->slug }}</td>
<td>{{ $fieldType->class }}</td>
<td>{{ $fieldType->active }}</td>

<td width="50">
<a href="{{ route('admin.field-types.edit', $fieldType->id) }}"><span uk-icon="icon: pencil;"></span></a>
</td>
</tr>
@endforeach
@endsection

@section('table-settings')

<script>
$(function() {
$('#data-table').DataTable({
"pageLength": 50,
"order": [[1, 'asc']]
});
});
</script>

@endsection

0 comments on commit bd173da

Please sign in to comment.
You can’t perform that action at this time.