edit multi-language models

This commit is contained in:
Arno Kaimbacher 2018-11-13 17:21:58 +01:00
parent 0e88d76bdc
commit ad42e73126
10 changed files with 351 additions and 119 deletions

View File

@ -81,20 +81,34 @@ class PageController extends Controller
/**
* Update the specified resource in storage.
*
* @param @param \App\Http\Requests\Pages\UpdatePageRequest $request
* @param \App\Models\Page $page
* @param \App\Http\Requests\Pages\UpdatePageRequest $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(UpdatePageRequest $request, Page $page) : RedirectResponse
public function update(UpdatePageRequest $request, $id)
{
$page = Page::findOrFail($id);
// $this->pages->update($page, $request->except(['_method', '_token']));
$input = $request->except(['_method', '_token']);
$input = $request
->except(['_method', '_token', 'nav-tab', 'en_title', 'en_description', 'de_title', 'de_description']);
// Making extra fields
//$input['page_slug'] = str_slug($input['title']);
$input['status'] = isset($input['status']) ? 1 : 0;
$input['updated_by'] = \Auth::user()->id;
if ($page->update($input)) {
$article_data = [
'en' => [
'title' => $request->input('en_title'),
'description' => $request->input('en_description')
],
'de' => [
'title' => $request->input('de_title'),
'description' => $request->input('de_description')
],
];
$ergebnis = array_merge($input, $article_data);
if ($page->update($ergebnis)) {
event(new PageUpdated($page));
return redirect()

View File

@ -16,7 +16,8 @@ class UpdatePageRequest extends Request
*/
public function authorize()
{
return true;//return access()->allow('edit-page');
return true;
//return access()->allow('edit-page');
}
/**
@ -27,8 +28,8 @@ class UpdatePageRequest extends Request
public function rules()
{
return [
'title' => 'required|max:191',
'description' => 'required',
'en_title' => 'required|max:191'
// 'description_en' => 'required'
];
}
}

View File

@ -6,7 +6,7 @@ use Illuminate\Validation\Rule;
//https://packagist.org/packages/felixkiss/uniquewith-validator
class CreatePersonRequest extends Request
class EditPersonRequest extends Request
{
/**
* Determine if the user is authorized to make this request.

View File

@ -2,6 +2,7 @@
namespace App\Models;
// 1. To specify packages class you are using
use App\Models\ModelTrait;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
@ -10,7 +11,11 @@ use Dimsav\Translatable\Translatable;
class Page extends Model
{
use ModelTrait;
use Translatable;
use Translatable; // 2. To add translation methods
// 3. To define which attributes needs to be translated
public $translatedAttributes = ['title', 'description'];
/**
* The database table used by the model.
*
@ -18,8 +23,6 @@ class Page extends Model
*/
protected $table;
public $translatedAttributes = ['title', 'description'];
/**
* The guarded field which are not mass assignable.
*

View File

@ -8,6 +8,6 @@ use Illuminate\Database\Eloquent\Model;
class PageTranslation extends Model
{
public $timestamps = false;
//protected $fillable = ['description'];
protected $fillable = ['title', 'description'];
protected $guarded = ['id'];
}

169
public/backend/tabs.css vendored Normal file
View File

@ -0,0 +1,169 @@
.tabs {
-webkit-overflow-scrolling: touch;
align-items: stretch;
display: flex;
font-size: 1rem;
justify-content: space-between;
overflow: hidden;
overflow-x: auto;
white-space: nowrap;
}
.tabs a {
align-items: center;
border-bottom-color: #dbdbdb;
border-bottom-style: solid;
border-bottom-width: 1px;
color: #4a4a4a;
display: flex;
justify-content: center;
margin-bottom: -1px;
padding: 0.5em 1em;
vertical-align: top;
}
.tabs a:hover {
border-bottom-color: #363636;
color: #363636;
}
.tabs li {
display: block;
}
.tabs li.is-active a {
border-bottom-color: #3273dc;
color: #3273dc;
}
.tabs ul {
align-items: center;
border-bottom-color: #dbdbdb;
border-bottom-style: solid;
border-bottom-width: 1px;
display: flex;
flex-grow: 1;
flex-shrink: 0;
justify-content: flex-start;
}
.tabs ul.is-left {
padding-right: 0.75em;
}
.tabs ul.is-center {
flex: none;
justify-content: center;
padding-left: 0.75em;
padding-right: 0.75em;
}
.tabs ul.is-right {
justify-content: flex-end;
padding-left: 0.75em;
}
.tabs .icon:first-child {
margin-right: 0.5em;
}
.tabs .icon:last-child {
margin-left: 0.5em;
}
.tabs.is-centered ul {
justify-content: center;
}
.tabs.is-right ul {
justify-content: flex-end;
}
.tabs.is-boxed a {
border: 1px solid transparent;
border-radius: 4px 4px 0 0;
}
.tabs.is-boxed a:hover {
background-color: whitesmoke;
border-bottom-color: #dbdbdb;
}
.tabs.is-boxed li.is-active a {
background-color: white;
border-color: #dbdbdb;
border-bottom-color: transparent !important;
}
.tabs.is-fullwidth li {
flex-grow: 1;
flex-shrink: 0;
}
.tabs.is-toggle a {
border-color: #dbdbdb;
border-style: solid;
border-width: 1px;
margin-bottom: 0;
position: relative;
}
.tabs.is-toggle a:hover {
background-color: whitesmoke;
border-color: #b5b5b5;
z-index: 2;
}
.tabs.is-toggle li + li {
margin-left: -1px;
}
.tabs.is-toggle li:first-child a {
border-radius: 4px 0 0 4px;
}
.tabs.is-toggle li:last-child a {
border-radius: 0 4px 4px 0;
}
.tabs.is-toggle li.is-active a {
background-color: #3273dc;
border-color: #3273dc;
color: #fff;
z-index: 1;
}
.tabs.is-toggle ul {
border-bottom: none;
}
.tabs.is-toggle.is-toggle-rounded li:first-child a {
border-bottom-left-radius: 290486px;
border-top-left-radius: 290486px;
padding-left: 1.25em;
}
.tabs.is-toggle.is-toggle-rounded li:last-child a {
border-bottom-right-radius: 290486px;
border-top-right-radius: 290486px;
padding-right: 1.25em;
}
.tabs.is-small {
font-size: 0.75rem;
}
.tabs.is-medium {
font-size: 1.25rem;
}
.tabs.is-large {
font-size: 1.5rem;
}
.tab-pane {
/* background-color: azure; */
/* border: 1px solid #dbdbdb; */
border-bottom: 1px solid #dbdbdb;
padding: 1rem 1rem 1rem 1rem;
}

View File

@ -15,6 +15,7 @@
<link rel="stylesheet" type="text/css" href="{{ asset('/backend/style.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('/backend/pagination.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('/backend/tabs.css') }}">
@yield('styles')
</head>
<body>

View File

@ -8,8 +8,9 @@
</h1>
@endsection
--}}
@section('content') {{ Form::model($page, ['method' => 'PATCH', 'route' => ['settings.page.update', $page],
'class' => 'pure-form pure-form-aligned', 'id' => 'edit-role', 'enctype' => 'multipart/form-data']) }}
@section('content')
{!! Form::model($page, ['method' => 'PATCH', 'route' => ['settings.page.update', $page->id],
'class' => 'pure-form pure-form-aligned', 'enctype' => 'multipart/form-data']) !!}
<div class="box box-info">
@ -24,119 +25,127 @@
<div class="box-body box-content">
<!-- Nav tabs -->
<input type="radio" id="english-option" name="nav-tab" type="hidden">
<input type="radio" id="german-option" name="nav-tab" type="hidden">
<div class="tabs is-boxed">
<ul>
<li class="english-link">
<label for="english-option"><a class="remove-check">EN</a></label>
</li>
<li class="german-link">
<label for="german-option"><a class="remove-check">DE</a></label>
</li>
</ul>
</div>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane content-pic" id="english-form">
<div class="pure-control-group">
{{ Form::label('title', trans('validation.attributes.backend.pages.title'), ['class' => 'col-lg-2 control-label required'])
}}
{!! Form::label('en_title', trans('validation.attributes.backend.pages.title'), ['class' => 'col-lg-2 control-label required'])
!!}
<div class="col-lg-10">
{{ Form::text('title', null, ['class' => 'form-control box-size', 'placeholder' => trans('validation.attributes.backend.pages.title'),
'required' => 'required', 'readonly' => 'true']) }}
{!! Form::text('en_title', $page->translate('en')->title, ['class' => 'form-control box-size', 'placeholder' => trans('validation.attributes.backend.pages.title'),
'required' => 'required', 'readonly' => 'true']) !!}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="pure-control-group">
{{ Form::label('description', trans('validation.attributes.backend.pages.description'), ['class' => 'col-lg-2 control-label
required']) }}
{!! Form::label('en_description', trans('validation.attributes.backend.pages.description'), ['class' => 'col-lg-2 control-label
required']) !!}
<div class="col-lg-10">
{{ Form::textarea('description', null,['class' => 'form-control', 'placeholder' => trans('validation.attributes.backend.pages.description')])
}}
{!! Form::textarea('en_description', $page->translate('en')->description, ['class' => 'form-control description', 'placeholder' => trans('validation.attributes.backend.pages.description')])
!!}
</div>
</div>
<!--col-lg-3-->
</div>
<!--form control-->
{{--
<div class="tab-pane content-music" id="german-form">
<div class="pure-control-group">
{{ Form::label('language', 'Language..', ['class' => 'col-lg-2 control-label required']) }}
{!! Form::label('de_title', trans('validation.attributes.backend.pages.title'), ['class' => 'col-lg-2 control-label required'])
!!}
<div class="col-lg-10">
{{ Form::select('language', $languages, $page->language, ['placeholder' => '--no language--']) }}
{!! Form::text('de_title', $page->translate('de')->title, ['class' => 'form-control box-size', 'placeholder' => trans('validation.attributes.backend.pages.title'),
'required' => 'required', 'readonly' => 'true']) !!}
</div>
</div>
<div class="pure-control-group">
{!! Form::label('de_description', trans('validation.attributes.backend.pages.description'), ['class' => 'col-lg-2 control-label
required']) !!}
<div class="col-lg-10">
{!! Form::textarea('de_description', $page->translate('de')->description, ['class' => 'form-control description', 'placeholder' => trans('validation.attributes.backend.pages.description')])
!!}
</div>
</div>
</div>
</div>
</div> --}}
<div class="pure-control-group">
{{ Form::label('cannonical_link', trans('validation.attributes.backend.pages.cannonical_link'), ['class' => 'col-lg-2 control-label'])
}}
<div class="col-lg-10">
{{ Form::text('cannonical_link', null, ['class' => 'form-control box-size', 'placeholder' => trans('validation.attributes.backend.pages.cannonical_link')])
}}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="pure-control-group">
{{ Form::label('seo_title', trans('validation.attributes.backend.pages.seo_title'), ['class' => 'col-lg-2 control-label'])
}}
<div class="col-lg-10">
{{ Form::text('seo_title', null, ['class' => 'form-control box-size', 'placeholder' => trans('validation.attributes.backend.pages.seo_title')])
}}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="pure-control-group">
{{ Form::label('seo_keyword', trans('validation.attributes.backend.pages.seo_keyword'), ['class' => 'col-lg-2 control-label'])
}}
<div class="col-lg-10">
{{ Form::text('seo_keyword', null, ['class' => 'form-control box-size', 'placeholder' => trans('validation.attributes.backend.pages.seo_keyword')])
}}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="pure-control-group">
{{ Form::label('seo_description', trans('validation.attributes.backend.pages.seo_description'), ['class' => 'col-lg-2 control-label'])
}}
<div class="col-lg-10">
{{ Form::textarea('seo_description', null,['class' => 'form-control', 'placeholder' => trans('validation.attributes.backend.pages.seo_description')])
}}
</div>
<!--col-lg-3-->
</div>
<!--form control-->
<div class="pure-control-group">
{{ Form::label('status', trans('validation.attributes.backend.pages.is_active'), ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{!! Form::label('status', trans('validation.attributes.backend.pages.is_active'), ['class' => 'col-lg-2 control-label']) !!}
<div class="control-group">
<label class="control control--checkbox">
{{ Form::checkbox('status', 1, ($page->status == 1) ? true : false ) }}
<div class="control__indicator"></div>
{!! Form::checkbox('status', 1, ($page->status == 1) ? true : false ) !!}
</label>
</div>
</div>
<!--col-lg-3-->
</div>
<!--form control-->
<div class="pure-controls">
{{ link_to_route('settings.page.index', trans('buttons.general.cancel'), [], ['class' => 'pure-button button-small is-warning'])
}} {{ Form::submit(trans('buttons.general.crud.update'), ['class' => 'pure-button button-small is-primary'])
}}
<div class="clearfix"></div>
{{ link_to_route('settings.page.index', trans('buttons.general.cancel'), [], ['class' => 'pure-button button-small is-warning']) }}
{!! Form::submit(trans('buttons.general.crud.update'), ['class' => 'pure-button button-small is-primary']) !!}
</div>
</div>
<!-- /.box-body -->
</div>
<!--box-->
{{ Form::close() }}
@include('errors._errors')
{!! Form::close() !!}
@endsection
@section('styles')
{{-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.2/css/bulma.min.css"/> --}}
<style type="text/css">
input[type="radio"], .tab-pane { display: none; }
#english-option:checked ~ .tab-content > .content-pic,
#german-option:checked ~ .tab-content > .content-music,
#video:checked ~ .tab-content > .content-video,
#doc:checked ~ .tab-content > .content-doc {
display: block;
}
#english-option:checked ~ .tabs .english-link a,
#german-option:checked ~ .tabs .german-link a {
/* border-bottom-color: #3273dc;
color: #3273dc; */
background-color: #3273dc;
border-color: #3273dc;
color: #fff;
z-index: 1;
}
</style>
@endsection
@section("after-scripts")
<script type="text/javascript">
// Backend.Pages.init();
</script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.10/summernote-lite.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.10/summernote-lite.js"></script>
<script>
$(document).ready(function() {
// $('#description').summernote();
$('#description').summernote({
$('.description').summernote({
height: "300px",
callbacks: {
// onImageUpload: function(files, editor, welEditable) {
@ -144,6 +153,26 @@
// }
}
});
document.getElementById("english-option").checked = true;
// var $englishForm = $('#english-form');
// var $germanForm = $('#german-form');
// var $englishLink = $('#english-link');
// var $germanLink = $('#german-link');
// $englishLink.click(function() {
// $englishLink.toggleClass('bg-aqua-active');
// $englishForm.toggleClass('hidden');
// $germanLink.toggleClass('bg-aqua-active');
// $germanForm.toggleClass('hidden');
// });
// $germanLink.click(function() {
// $englishLink.toggleClass('bg-aqua-active');
// $englishForm.toggleClass('hidden');
// $germanLink.toggleClass('bg-aqua-active');
// $germanForm.toggleClass('hidden');
// });
});
</script>
@endsection

View File

@ -53,7 +53,9 @@
<td>{{ $person->documents->count() }}</td>
<td>
<a class="edit" href="{{ route('settings.person.edit', $person->id) }}"><span>&nbsp;</span></a>
@if($person->documents->count() == 0)
<a class="delete" href="{{ route('settings.person.delete', $person->id) }}"><span>&nbsp;</span></a>
@endif
</td>
</tr>
@endforeach

View File

@ -90,15 +90,28 @@ Route::group(
/*
* CMS Pages Management=============================================================================
*/
Route::group(['namespace' => 'Settings', 'prefix' => 'settings', 'as' => 'settings.',], function () {
Route::resource('page', 'PageController', ['except' => ['show', 'update']]);
Route::patch('page/{page}', [
Route::group(
[
'middleware' => ['permission:settings'],
'namespace' => 'Settings',
'prefix' => 'settings',
'as' => 'settings.'
],
function () {
//Route::resource('page', 'PageController', ['except' => ['show', 'update']]);
Route::get('user', [
'as' => 'page.index', 'uses' => 'PageController@index',
]);
Route::get('page/edit/{page}', [
'as' => 'page.edit', 'uses' => 'PageController@edit',
]);
Route::patch('page/update/{id}', [
'as' => 'page.update', 'uses' => 'PageController@update',
]);
// //For DataTables
Route::get('pages/get', ['uses' => 'PagesTableController@get'])->name('page.get');
});
}
);
//=================================================setting home - dashboard=======================================