Commit c0b6ddf3 by Aan Choesni Herlingga

translate en page

parent f47c9885
......@@ -132,7 +132,7 @@ class CategoryController extends Controller
{
$dataEn['name'] = $data['name_en'];
$this->repo->update($dataEn, $category->rEn);
$this->repoEn->update($dataEn, $category->rEn);
}
/**
......
......@@ -5,15 +5,24 @@ namespace App\Http\Controllers\Webprofile\Backend;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Webprofile\Categories;
use App\Repositories\Webprofile\En\PagesRepository as EnPagesRepository;
use App\Repositories\Webprofile\PagesRepository;
use Statickidz\GoogleTranslate;
class PageController extends Controller
{
private $repo;
private $repoEn;
public function __construct(PagesRepository $repo)
{
private $SOURCE = 'id';
private $TARGET = 'en';
public function __construct(
PagesRepository $repo,
EnPagesRepository $repoEn
){
$this->repo = $repo;
$this->repoEn = $repoEn;
}
/**
* Display a listing of the resource.
......@@ -56,11 +65,27 @@ class PageController extends Controller
{
$data = $request->except('_token');
$this->repo->store($data);
$save = $this->repo->store($data);
// save translate
$this->createEn($data, $save);
return redirect()->route('pages.index');
}
private function createEn($data, $page)
{
$trans = new GoogleTranslate();
$title = $trans->translate($this->SOURCE, $this->TARGET, $data['title']);
$content = $trans->translate($this->SOURCE, $this->TARGET, strip_tags($data['content']));
$dataEn['page_id'] = $page->id;
$dataEn['title'] = $title;
$dataEn['content'] = $content;
$this->repoEn->store($dataEn);
}
/**
* Display the specified resource.
*
......@@ -100,14 +125,25 @@ class PageController extends Controller
*/
public function update(Request $request, $id)
{
$data = $request->except(['_token', 'id']);
$data = $request->except(['_token', 'id', 'title_en', 'content_en']);
$dataEn = $request->except(['_token', 'id']);
$page = $this->repo->findId($id);
$edit = $this->repo->update($data, $page);
$this->updateEn($dataEn, $page);
return redirect()->route('pages.index');
}
public function updateEn($data, $page)
{
$dataEn['title'] = $data['title_en'];
$dataEn['content'] = $data['content_en'];
$this->repoEn->update($dataEn, $page->rEn);
}
/**
* Remove the specified resource from storage.
*
......
......@@ -148,7 +148,7 @@ class PostController extends Controller
$dataEn['title'] = $data['title_en'];
$dataEn['content'] = $data['content_en'];
$this->repo->update($dataEn, $post->rEn);
$this->repoEn->update($dataEn, $post->rEn);
}
/**
......
<?php
namespace App\Models\Webprofile\En;
use App\Http\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Model;
class Pages extends Model
{
use UuidTrait;
public $incrementing = false;
protected $table = 'swp_pages_en';
protected $guarded = [];
}
......@@ -5,6 +5,7 @@ namespace App\Models\Webprofile;
use App\Http\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Model;
use App\Models\Webprofile\Categories;
use App\Models\Webprofile\En\Pages as EnPages;
class Pages extends Model
{
......@@ -14,4 +15,9 @@ class Pages extends Model
protected $table = 'swp_pages';
protected $guarded = [];
public function rEn()
{
return $this->hasOne(EnPages::class, 'page_id', 'id');
}
}
<?php
namespace App\Repositories\Webprofile\En;
use App\Models\Webprofile\En\Pages;
use App\Repositories\Repository;
use Illuminate\Database\Eloquent\Model;
class PagesRepository extends Repository
{
public function __construct(Pages $model)
{
$this->model = $model;
}
public function get()
{
}
public function paginate()
{
}
}
......@@ -49,7 +49,13 @@ class PagesRepository extends Repository
return $str;
})
->rawColumns(['action', 'sum'])
->addColumn('title', function ($row) {
$str = $row->title . '<br>';
$str .= '<i style="color: blue;">' . $row->rEn->title . '</i>';
return $str;
})
->rawColumns(['action', 'sum', 'title'])
->make(true);
}
}
......@@ -30,10 +30,13 @@
</div>
<div class="panel-body">
<div class="row">
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
Bahasa Indonesia
</div>
<div class="col-md-12">
<div class="form-group @if ($errors->has('title')) has-error @endif">
<div class="col-md-12">
{{ Form::text('title', old('title'), array('class' => 'form-control', 'placeholder'=>app('translator')->getFromJson('label.title'), 'style'=>'font-size: 14pt;')) }}
{{ Form::text('title', old('title'), array('class' => 'form-control', 'placeholder'=>trans('label.title'), 'style'=>'font-size: 14pt;')) }}
@if ($errors->has('title'))
<label id="login-error" class="error" for="login">{{$errors->first('title')}}</label>
@endif
......@@ -46,6 +49,34 @@
</div>
</div>
</div>
<div class="row">
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
English Language
</div>
<div class="col-md-12">
<div class="form-group @if ($errors->has('title')) has-error @endif">
<div class="col-md-12">
@if($data->rEn)
{{ Form::text('title_en', $data->rEn->title, array('class' => 'form-control', 'placeholder'=>trans('label.title'), 'style'=>'font-size: 14pt;')) }}
@else
{{ Form::text('title_en', null, array('class' => 'form-control', 'placeholder'=>trans('label.title'), 'style'=>'font-size: 14pt;')) }}
@endif
@if ($errors->has('title'))
<label id="login-error" class="error" for="login">{{$errors->first('title')}}</label>
@endif
</div>
</div>
</div>
<div class="col-md-12">
<div class="block">
@if ($data->rEn)
{{ Form::textarea('content_en', $data->rEn->content, array('id'=>'content_en')) }}
@else
{{ Form::textarea('content_en', null, array('id'=>'content_en')) }}
@endif
</div>
</div>
</div>
</div>
</div>
</div>
......@@ -83,6 +114,9 @@
$('#content').summernote({
height: 400
});
$('#content_en').summernote({
height: 400
});
});
$('#categories').select2();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment