Commit 922f08b6 by Aan Choesni Herlingga

translate en information

parent 6106797a
......@@ -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\InformationRepository as EnInformationRepository;
use App\Repositories\Webprofile\InformationRepository;
use Statickidz\GoogleTranslate;
class InformationController extends Controller
{
private $repo;
private $repoEn;
public function __construct(InformationRepository $repo)
{
private $SOURCE = 'id';
private $TARGET = 'en';
public function __construct(
InformationRepository $repo,
EnInformationRepository $repoEn
){
$this->repo = $repo;
$this->repoEn = $repoEn;
}
/**
* Display a listing of the resource.
......@@ -58,11 +67,27 @@ class InformationController extends Controller
array_key_exists('info_status', $data) ? $data['info_status'] = 1 : $data['info_status'] = 0;
$this->repo->store($data);
$save = $this->repo->store($data);
// save translate
$this->createEn($data, $save);
return redirect()->route('informations.index');
}
private function createEn($data, $information)
{
$trans = new GoogleTranslate();
$title = $trans->translate($this->SOURCE, $this->TARGET, $data['title']);
$content = $trans->translate($this->SOURCE, $this->TARGET, strip_tags($data['content']));
$dataEn['information_id'] = $information->id;
$dataEn['title'] = $title;
$dataEn['content'] = $content;
$this->repoEn->store($dataEn);
}
/**
* Display the specified resource.
*
......@@ -102,16 +127,27 @@ class InformationController 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']);
array_key_exists('info_status', $data) ? $data['info_status'] = 1 : $data['info_status'] = 0;
$information = $this->repo->findId($id);
$information = $this->repo->findId($id, ['rEn']);
$edit = $this->repo->update($data, $information);
$this->updateEn($dataEn, $information);
return redirect()->route('informations.index');
}
public function updateEn($data, $information)
{
$dataEn['title'] = $data['title_en'];
$dataEn['content'] = $data['content_en'];
$this->repoEn->update($dataEn, $information->rEn);
}
/**
* Remove the specified resource from storage.
*
......
......@@ -128,7 +128,7 @@ class PageController extends Controller
$data = $request->except(['_token', 'id', 'title_en', 'content_en']);
$dataEn = $request->except(['_token', 'id']);
$page = $this->repo->findId($id);
$page = $this->repo->findId($id, ['rEn']);
$edit = $this->repo->update($data, $page);
$this->updateEn($dataEn, $page);
......
<?php
namespace App\Models\Webprofile\En;
use App\Http\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Model;
class Information extends Model
{
use UuidTrait;
public $incrementing = false;
protected $table = 'swp_informations_en';
protected $guarded = [];
}
......@@ -3,6 +3,7 @@
namespace App\Models\Webprofile;
use App\Http\Traits\UuidTrait;
use App\Models\Webprofile\En\Information as EnInformation;
use Illuminate\Database\Eloquent\Model;
class Information extends Model
......@@ -13,4 +14,9 @@ class Information extends Model
protected $table = 'swp_informations';
protected $guarded = [];
public function rEn()
{
return $this->hasOne(EnInformation::class, 'information_id', 'id');
}
}
<?php
namespace App\Repositories\Webprofile\En;
use App\Models\Webprofile\En\Information;
use App\Repositories\Repository;
use Illuminate\Database\Eloquent\Model;
class InformationRepository extends Repository
{
public function __construct(Information $model)
{
$this->model = $model;
}
public function get()
{
}
public function paginate()
{
}
}
......@@ -56,7 +56,13 @@ class InformationRepository extends Repository
}
return $str;
})
->rawColumns(['action', 'status', 'date'])
->addColumn('title', function ($row) {
$str = $row->title . '<br>';
$str .= '<i style="color: blue;">' . $row->rEn->title . '</i>';
return $str;
})
->rawColumns(['action', 'status', 'date', 'title'])
->make(true);
}
}
......@@ -20,6 +20,7 @@ class CreateInformationsEnTable extends Migration
$table->text('content')->nullable();
$table->string('userid_created', 36)->nullable();
$table->string('userid_updated', 36)->nullable();
$table->timestamps();
});
}
......
......@@ -30,6 +30,9 @@
</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">
......@@ -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>
......@@ -121,6 +152,9 @@
$('#content').summernote({
height: 400
});
$('#content_en').summernote({
height: 400
});
});
</script>
@stop
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