Commit 35af22e0 by Aan Choesni Herlingga

translate en category post

parent 0e3beec8
...@@ -5,14 +5,23 @@ namespace App\Http\Controllers\Webprofile\Backend; ...@@ -5,14 +5,23 @@ namespace App\Http\Controllers\Webprofile\Backend;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Repositories\Webprofile\CategoryRepository; use App\Repositories\Webprofile\CategoryRepository;
use App\Repositories\Webprofile\En\CategoryRepository as EnCategoryRepository;
use Statickidz\GoogleTranslate;
class CategoryController extends Controller class CategoryController extends Controller
{ {
private $repo; private $repo;
private $repoEn;
public function __construct(CategoryRepository $repo) private $SOURCE = 'id';
{ private $TARGET = 'en';
public function __construct(
CategoryRepository $repo,
EnCategoryRepository $repoEn
){
$this->repo = $repo; $this->repo = $repo;
$this->repoEn = $repoEn;
} }
/** /**
* Display a listing of the resource. * Display a listing of the resource.
...@@ -51,11 +60,24 @@ class CategoryController extends Controller ...@@ -51,11 +60,24 @@ class CategoryController extends Controller
array_key_exists('is_active', $data) ? $data['is_active'] = 1 : $data['is_active'] = 0; array_key_exists('is_active', $data) ? $data['is_active'] = 1 : $data['is_active'] = 0;
$this->repo->store($data); $category = $this->repo->store($data);
$this->createEn($data, $category);
return redirect()->route('category.index'); return redirect()->route('category.index');
} }
private function createEn($data, $category)
{
$trans = new GoogleTranslate();
$name = $trans->translate($this->SOURCE, $this->TARGET, $data['name']);
$dataEn['category_id'] = $category->id;
$dataEn['name'] = $name;
$this->repoEn->store($dataEn);
}
/** /**
* Display the specified resource. * Display the specified resource.
* *
...@@ -93,16 +115,26 @@ class CategoryController extends Controller ...@@ -93,16 +115,26 @@ class CategoryController extends Controller
*/ */
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
$data = $request->except(['_token', 'id']); $data = $request->except(['_token', 'id', 'name_en']);
$dataEn = $request->except(['_token', 'id']);
array_key_exists('is_active', $data) ? $data['is_active'] = 1 : $data['is_active'] = 0; array_key_exists('is_active', $data) ? $data['is_active'] = 1 : $data['is_active'] = 0;
$category = $this->repo->findId($id); $category = $this->repo->findId($id, ['rEn']);
$edit = $this->repo->update($data, $category); $edit = $this->repo->update($data, $category);
$this->updateEn($dataEn, $category);
return redirect()->route('category.index'); return redirect()->route('category.index');
} }
public function updateEn($data, $category)
{
$dataEn['name'] = $data['name_en'];
$this->repo->update($dataEn, $category->rEn);
}
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
* *
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace App\Models\Webprofile; namespace App\Models\Webprofile;
use App\Http\Traits\UuidTrait; use App\Http\Traits\UuidTrait;
use App\Models\Webprofile\En\Categories as EnCategories;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class Categories extends Model class Categories extends Model
...@@ -18,4 +19,9 @@ class Categories extends Model ...@@ -18,4 +19,9 @@ class Categories extends Model
{ {
return $this->hasMany(Posts::class, 'id', 'categories'); return $this->hasMany(Posts::class, 'id', 'categories');
} }
public function rEn()
{
return $this->hasOne(EnCategories::class, 'category_id', 'id');
}
} }
<?php
namespace App\Models\Webprofile\En;
use App\Http\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Model;
class Categories extends Model
{
use UuidTrait;
public $incrementing = false;
protected $table = 'swp_categories_en';
protected $guarded = [];
}
...@@ -51,7 +51,15 @@ class CategoryRepository extends Repository ...@@ -51,7 +51,15 @@ class CategoryRepository extends Repository
} }
return $str; return $str;
}) })
->rawColumns(['action', 'status']) ->addColumn('name', function ($row) {
$str = $row->name . '<br>';
if ($row->rEn) {
$str .= '<i style="color: blue;">' . $row->rEn->name . '</i>';
}
return $str;
})
->rawColumns(['action', 'status', 'name'])
->make(true); ->make(true);
} }
} }
<?php
namespace App\Repositories\Webprofile\En;
use App\Models\Webprofile\En\Categories;
use App\Repositories\Repository;
class CategoryRepository extends Repository
{
public function __construct(Categories $model)
{
$this->model = $model;
}
public function get()
{
}
public function paginate()
{
}
}
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="row"> <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="col-md-12">
<div class="form-group @if ($errors->has('name')) has-error @endif"> <div class="form-group @if ($errors->has('name')) has-error @endif">
<label class="col-md-2 control-label">Kategori</label> <label class="col-md-2 control-label">Kategori</label>
...@@ -31,6 +34,22 @@ ...@@ -31,6 +34,22 @@
@endif @endif
</div> </div>
</div> </div>
</div>
<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('name_en')) has-error @endif">
<label class="col-md-2 control-label">Category</label>
<div class="col-md-10">
{{ Form::text('name_en', $data->rEn->name, array('class' => 'form-control')) }}
@if ($errors->has('name_en'))
<label id="login-error" class="error" for="login">{{$errors->first('name_en')}}</label>
@endif
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group" style="padding-top: 10px;"> <div class="form-group" style="padding-top: 10px;">
<label class="col-md-2 control-label">Status</label> <label class="col-md-2 control-label">Status</label>
<div class="col-md-10"> <div class="col-md-10">
......
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