Multilingual config:
'multilingual' => [
/*
* Set whether or not the multilingual is supported by the BREAD input.
*/
'bread' => true,
/*
* Select default language
*/
'default' => 'ar',
/*
* Select languages that are supported.
*/
'locales' => [
'ar',
'en',
],
],
customized resource/views/vendor/voyager/posts/edit-add.blade.php contents:
@extends('voyager::master')
@section('css')
<meta name="csrf-token" content="{{ csrf_token() }}">
@stop
@if(isset($dataTypeContent->id))
@section('page_title','Edit '.$dataType->display_name_singular)
@else
@section('page_title','Add '.$dataType->display_name_singular)
@endif
@section('page_header')
<h1 class="page-title">
<i class="{{ $dataType->icon }}"></i> @if(isset($dataTypeContent->id)){{ 'Edit' }}@else{{ 'New' }}@endif {{ $dataType->display_name_singular }}
</h1>
@include('voyager::multilingual.language-selector')
@stop
@section('content')
<div class="page-content container-fluid">
<div class="row">
<div class="col-md-12">
<div class="panel panel-bordered">
<div class="panel-heading">
<h3 class="panel-title">@if(isset($dataTypeContent->id)){{ 'Edit' }}@else{{ 'Add New' }}@endif {{ $dataType->display_name_singular }}</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form role="form"
class="form-edit-add"
action="@if(isset($dataTypeContent->id)){{ route('voyager.'.$dataType->slug.'.update', $dataTypeContent->id) }}@else{{ route('voyager.'.$dataType->slug.'.store') }}@endif"
method="POST" enctype="multipart/form-data">
<!-- PUT Method if we are editing -->
@if(isset($dataTypeContent->id))
{{ method_field("PUT") }}
@endif
<!-- CSRF TOKEN -->
{{ csrf_field() }}
<div class="panel-body">
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<!-- If we are editing -->
@if(isset($dataTypeContent->id))
<?php $dataTypeRows = $dataType->editRows; ?>
@else
<?php $dataTypeRows = $dataType->addRows; ?>
@endif
@foreach($dataTypeRows as $row)
<div class="form-group @if($row->type == 'hidden') hidden @endif">
<label for="name">{{ $row->display_name }}</label>
@include('voyager::multilingual.input-hidden-bread')
@if(isset($dataTypeContent->id) && $row->type == 'rich_text_box')
<textarea class="richTextBox" name="{{$row->field}}"
style="border:0px;">@if(isset($dataTypeContent->{$row->field})){{ $dataTypeContent->{$row->field} }}@endif</textarea>
@else
{!! app('voyager')->formField($row, $dataType, $dataTypeContent) !!}
@foreach (app('voyager')->afterFormFields($row, $dataType, $dataTypeContent) as $after)
{!! $after->handle($row, $dataType, $dataTypeContent) !!}
@endforeach
@endif
</div>
@endforeach
@if(!isset($dataTypeContent->id))
<div class="form-group">
<label for="name">Add to Slider</label>
<input type="checkbox" name="add_to_slider">
</div>
@endif
</div><!-- panel-body -->
<div class="panel-footer">
<button type="submit" class="btn btn-primary save">Save</button>
</div>
</form>
<iframe id="form_target" name="form_target" style="display:none"></iframe>
<form id="my_form" action="{{ route('voyager.upload') }}" target="form_target" method="post"
enctype="multipart/form-data" style="width:0;height:0;overflow:hidden">
<input name="image" id="upload_file" type="file"
onchange="$('#my_form').submit();this.value='';">
<input type="hidden" name="type_slug" id="type_slug" value="{{ $dataType->slug }}">
{{ csrf_field() }}
</form>
</div>
</div>
</div>
</div>
<div class="modal fade modal-danger" id="confirm_delete_modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title"><i class="voyager-warning"></i> Are You Sure</h4>
</div>
<div class="modal-body">
<h4>Are you sure you want to delete '<span class="confirm_delete_name"></span>'</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" id="confirm_delete">Yes, Delete it!
</button>
</div>
</div>
</div>
</div>
<!-- End Delete File Modal -->
@stop
@section('javascript')
<script>
var params = {}
var $image
$('document').ready(function () {
$('.toggleswitch').bootstrapToggle();
@if ($isModelTranslatable)
$('.side-body').multilingual({"editing": true});
@endif
$('.side-body input[data-slug-origin]').each(function (i, el) {
$(el).slugify();
});
$('.form-group').on('click', '.remove-multi-image', function (e) {
$image = $(this).parent().siblings('img');
params = {
slug: '{{ $dataTypeContent->getTable() }}',
image: $image.data('image'),
id: $image.data('id'),
field: $image.parent().data('field-name'),
_token: '{{ csrf_token() }}'
}
$('.confirm_delete_name').text($image.data('image'));
$('#confirm_delete_modal').modal('show');
});
$('#confirm_delete').on('click', function () {
$.post('{{ route('voyager.media.remove') }}', params, function (response) {
if (response
&& response.data
&& response.data.status
&& response.data.status == 200) {
toastr.success(response.data.message);
$image.parent().fadeOut(300, function () {
$(this).remove();
})
} else {
toastr.error("Error removing image.");
}
});
$('#confirm_delete_modal').modal('hide');
});
});
</script>
@if($isModelTranslatable)
<script src="{{ config('voyager.assets_path') }}/js/multilingual.js"></script>
@endif
<script src="{{ config('voyager.assets_path') }}/lib/js/tinymce/tinymce.min.js"></script>
<script src="{{ config('voyager.assets_path') }}/js/voyager_tinymce.js"></script>
<script src="{{ config('voyager.assets_path') }}/js/slugify.js"></script>
@stop
error log:
in PDOConnection.php line 43
at FatalErrorException->__construct() in HandleExceptions.php line 133
at HandleExceptions->fatalExceptionFromError() in HandleExceptions.php line 119
at HandleExceptions->handleShutdown() in HandleExceptions.php line 0
at PDOConnection->__construct() in Connector.php line 65
at Connector->createPdoConnection() in Connector.php line 43
at Connector->createConnection() in MySqlConnector.php line 24
at MySqlConnector->connect() in ConnectionFactory.php line 183
at ConnectionFactory->Illuminate\Database\Connectors\{closure}() in Connection.php line 882
at call_user_func:{C:\wamp\www\hzm-vcms\vendor\laravel\framework\src\Illuminate\Database\Connection.php:882}() in Connection.php line 882
at Connection->getPdo() in Connection.php line 903
at Connection->getReadPdo() in Connection.php line 392
at Connection->getPdoForSelect() in Connection.php line 318
at Connection->Illuminate\Database\{closure}() in Connection.php line 640
at Connection->runQueryCallback() in Connection.php line 607
at Connection->run() in Connection.php line 326
at Connection->select() in Builder.php line 1711
at Builder->runSelect() in Builder.php line 1696
at Builder->get() in Builder.php line 462
at Builder->getModels() in Builder.php line 446
at Builder->get() in Model.php line 336
at Model::all() in voyager.php line 34
at Voyager->{closure:C:\wamp\www\hzm-vcms\vendor\tcg\voyager\routes\voyager.php:23-111}() in Router.php line 310
at Router->loadRoutes() in Router.php line 270
at Router->group() in Facade.php line 221
at Facade::__callStatic() in voyager.php line 111
at Facade::group() in voyager.php line 111
at Voyager->{closure:C:\wamp\www\hzm-vcms\vendor\tcg\voyager\routes\voyager.php:15-112}() in Router.php line 310
at Router->loadRoutes() in Router.php line 270
at Router->group() in Facade.php line 221
at Facade::__callStatic() in voyager.php line 112
at Facade::group() in voyager.php line 112
in Voyager.php line 159
at Voyager->routes() in Facade.php line 221
at Facade::__callStatic() in web.php line 106
at Facade::routes() in web.php line 106
at RouteServiceProvider->{closure:C:\wamp\www\hzm-vcms\routes\web.php:105-107}() in Router.php line 310
at Router->loadRoutes() in Router.php line 270
at Router->group() in Facade.php line 221
at Facade::__callStatic() in web.php line 107
at Facade::group() in web.php line 107
in RouteServiceProvider.php line 58
at RouteServiceProvider->App\Providers\{closure}() in Router.php line 310
at Router->loadRoutes() in Router.php line 270
at Router->group() in Facade.php line 221
at Facade::__callStatic() in RouteServiceProvider.php line 59
at Facade::group() in RouteServiceProvider.php line 59
at RouteServiceProvider->mapWebRoutes() in RouteServiceProvider.php line 40
at RouteServiceProvider->map() in BoundMethod.php line 29
at call_user_func_array:{C:\wamp\www\hzm-vcms\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:29}() in BoundMethod.php line 29
at BoundMethod::Illuminate\Container\{closure}() in BoundMethod.php line 87
at BoundMethod::callBoundMethod() in BoundMethod.php line 31
at BoundMethod::call() in Container.php line 531
at Container->call() in RouteServiceProvider.php line 70
at RouteServiceProvider->loadRoutes() in RouteServiceProvider.php line 30
at RouteServiceProvider->boot() in RouteServiceProvider.php line 28
at RouteServiceProvider->boot() in BoundMethod.php line 29
at call_user_func_array:{C:\wamp\www\hzm-vcms\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:29}() in BoundMethod.php line 29
at BoundMethod::Illuminate\Container\{closure}() in BoundMethod.php line 87
at BoundMethod::callBoundMethod() in BoundMethod.php line 31
at BoundMethod::call() in Container.php line 531
at Container->call() in Application.php line 762
at Application->bootProvider() in Application.php line 745
at Application->Illuminate\Foundation\{closure}() in Application.php line 746
at array_walk() in Application.php line 746
at Application->boot() in BootProviders.php line 17
at BootProviders->bootstrap() in Application.php line 208
at Application->bootstrapWith() in Kernel.php line 160
at Kernel->bootstrap() in Kernel.php line 144
at Kernel->sendRequestThroughRouter() in Kernel.php line 116
at Kernel->handle() in index.php line 53
at {main}() in index.php line 0
This might be related to a known bug, when the user changes the default language en to another locale, system will crash.
@marktopper remember this? we need to write that command in order to fix this :)
@EngHazem is your site working with translations, or it fails when you try to update a post?
Check for the translations table, you should see records for locale="en", and the ar translations should be located in the post table. If your system is different, then you are being affected by this bug.
If your issue is related to this, you may try the following:
ar.ar locale is saved at post table, and the en in translations.@akazorg
I tested it and what happened is that only the body field is inserted to translations table with locale en and empty value, but no records add for other translatable records like title, .... etc
Please check this code I edited in the edit-add template to solve the problem of that the rich text editor is not loaded with the full HTML syntax of the body, instead it is loaded with the plain text..
@foreach($dataTypeRows as $row)
<div class="form-group @if($row->type == 'hidden') hidden @endif">
<label for="name">{{ $row->display_name }}</label>
@include('voyager::multilingual.input-hidden-bread')
@if(isset($dataTypeContent->id) && $row->type == 'rich_text_box')
<textarea class="richTextBox" name="{{$row->field}}"
style="border:0px;">@if(isset($dataTypeContent->{$row->field})){{ $dataTypeContent->{$row->field} }}@endif</textarea>
@else
{!! app('voyager')->formField($row, $dataType, $dataTypeContent) !!}
@foreach (app('voyager')->afterFormFields($row, $dataType, $dataTypeContent) as $after)
{!! $after->handle($row, $dataType, $dataTypeContent) !!}
@endforeach
@endif
</div>
@endforeach
instead of ..
@foreach($dataTypeRows as $row)
<div class="form-group @if($row->type == 'hidden') hidden @endif">
<label for="name">{{ $row->display_name }}</label>
@include('voyager::multilingual.input-hidden-bread')
{!! app('voyager')->formField($row, $dataType, $dataTypeContent) !!}
@foreach (app('voyager')->afterFormFields($row, $dataType, $dataTypeContent) as $after)
{!! $after->handle($row, $dataType, $dataTypeContent) !!}
@endforeach
</div>
@endforeach
could this be related to the problem ?
I can reproduce the bug of the rich-text loosing the html. I will fix this later.
Your issue, however, seams to be related to the bug I described before.
Text me on slack, we will figure out something.
@EngHazem we've been working on this, some bugs were fixed, check out Pull Requests for more info.
The html strip tags was also fixed #1019.
@marktopper is working on a command for changing the default locale. I'm sure you will need it in order to work that way.
Thanks @akazorg
I tested it and it worked.
Great men!
I hope you don't need to use + maintain a custom blade anymore.
There is a bug when you insert new records, but I've sent a PR for that.
The menu is also not working well on insert, but there's a fix in progress. I'll leave the translations fully working, bug free!! (hopefully xD).
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
Great men!
I hope you don't need to use + maintain a custom blade anymore.
There is a bug when you insert new records, but I've sent a PR for that.
The menu is also not working well on insert, but there's a fix in progress. I'll leave the translations fully working, bug free!! (hopefully xD).