Commit b1f1e29c by Triyah Fatmawati

Mengupdate fitur edit kategori untuk auto translate dan edit per bahasa

parent cc6756fb
......@@ -151,14 +151,30 @@ class CategoryController extends Controller
public function edit($id)
{
$data = $this->repo->findId($id, ['rEn', 'rDe', 'rSa', 'rZh']);
$manual=0;
$data = [
'data' => $data,
'manual' => $manual,
];
return view('webprofile.backend.categories.edit', $data)->withTitle(trans('feature.edit_category'));
}
public function editPerBahasa($id)
{
$data = $this->repo->findId($id, ['rEn', 'rDe', 'rSa', 'rZh']);
$manual=1;
$data = [
'data' => $data,
'manual' => $manual,
];
// dd($data);
return view('webprofile.backend.categories.edit_per_bahasa', $data)->withTitle(trans('feature.edit_category'));
}
/**
* Update the specified resource in storage.
*
......@@ -168,77 +184,139 @@ class CategoryController extends Controller
*/
public function update(Request $request, $id)
{
$data = $request->except(['_token', 'id', 'name_en', 'name_de', 'name_sa', 'name_zh']);
$dataEn = $request->except(['_token', 'id', 'name_de']);
$dataDe = $request->except(['_token', 'id', 'name', 'name_en']);
$data = $request->except(['_token', 'manual', 'id', 'name_en', 'name_de', 'name_sa', 'name_zh']);
// $dataEn = $request->except(['_token', 'id', 'name_de']);
$dataEn = $request->except(['_token','id', 'manual']);
// $dataDe = $request->except(['_token', 'id', 'name', 'name_en']);
// dd($dataEn);
array_key_exists('is_active', $data) ? $data['is_active'] = 1 : $data['is_active'] = 0;
$category = $this->repo->findId($id, ['rEn', 'rDe', 'rSa', 'rZh']);
$edit = $this->repo->update($data, $category);
$this->updateEn($dataEn, $category);
$this->updateDe($dataDe, $category);
$this->updateSa($dataEn, $category);
$this->updateZh($dataEn, $category);
// $edit = $this->repo->update($data, $category);
// dd($dataEn, $category, $request->manual);
$this->updateEn($dataEn, $category, $request->manual);
$this->updateDe($dataEn, $category, $request->manual);
$this->updateSa($dataEn, $category, $request->manual);
$this->updateZh($dataEn, $category, $request->manual);
$this->repo->update($data, $category);
// dd($data, $category, $request->manual);
return redirect()->route('category.index');
}
public function updateEn($data, $category)
public function updateEn($data, $category, $manual)
{
$dataEn['name'] = $data['name_en'];
if ($category->rEn) {
$this->repoDe->update($dataEn, $category->rEn);
} else {
$dataEn['category_id'] = $category->id;
$dataEn['name'] = $data['name_en'];
$this->repoEn->store($dataEn);
}
// $dataEn['name'] = $data['name_en'];
// if ($category->rEn) {
// $this->repoDe->update($dataEn, $category->rEn);
// } else {
// $dataEn['category_id'] = $category->id;
// $dataEn['name'] = $data['name_en'];
// $this->repoEn->store($dataEn);
// }
// dd($data, $category, $manual);
if($manual==1){
$dataEn['name'] = $data['name_en'];
}
else{
if (strip_tags($data['name']) == null) {
$data['name'] = 'kosong';
}
$trans = new GoogleTranslate();
$name = $trans->translate($this->SOURCE, $this->TARGET, $data['name']);
$dataEn['name'] = $name;
// dd($dataEn);
}
// dd($category);
$this->repoEn->update($dataEn, $category);
}
public function updateDe($data, $category)
public function updateDe($data, $category, $manual)
{
$dataDe['name'] = $data['name_de'];
// $dataDe['name'] = $data['name_de'];
// if ($category->rDe) {
// $this->repoDe->update($dataDe, $category->rDe);
// } else {
// $dataDe['category_id'] = $category->id;
// $dataDe['name'] = $data['name_de'];
// $this->repoDe->store($dataDe);
// }
if ($category->rDe) {
$this->repoDe->update($dataDe, $category->rDe);
} else {
$dataDe['category_id'] = $category->id;
if($manual==1){
$dataDe['name'] = $data['name_de'];
}
else{
if (strip_tags($data['name']) == null) {
$data['name'] = 'kosong';
}
$this->repoDe->store($dataDe);
$trans = new GoogleTranslate();
$name = $trans->translate($this->SOURCE, $this->TARGETDE, $data['name']);
$dataDe['name'] = $name;
}
$this->repoDe->update($dataDe, $category);
}
public function updateSa($data, $category)
public function updateSa($data, $category, $manual)
{
$dataSa['name'] = $data['name_sa'];
// $dataSa['name'] = $data['name_sa'];
// if ($category->rSa) {
// $this->repoSa->update($dataSa, $category->rSa);
// } else {
// $dataSa['category_id'] = $category->id;
// $dataSa['name'] = $data['name_sa'];
if ($category->rSa) {
$this->repoSa->update($dataSa, $category->rSa);
} else {
$dataSa['category_id'] = $category->id;
// $this->repoSa->store($dataSa);
// }
if($manual==1){
$dataSa['name'] = $data['name_sa'];
}
else{
if (strip_tags($data['name']) == null) {
$data['name'] = 'kosong';
}
$this->repoSa->store($dataSa);
$trans = new GoogleTranslate();
$name = $trans->translate($this->SOURCE, $this->TARGETSA, $data['name']);
$dataSa['name'] = $name;
}
$this->repoSa->update($dataSa, $category);
}
public function updateZh($data, $category)
public function updateZh($data, $category, $manual)
{
$dataZh['name'] = $data['name_zh'];
// $dataZh['name'] = $data['name_zh'];
// if ($category->rZh) {
// $this->repoZh->update($dataZh, $category->rZh);
// } else {
// $dataZh['category_id'] = $category->id;
// $dataZh['name'] = $data['name_zh'];
if ($category->rZh) {
$this->repoZh->update($dataZh, $category->rZh);
} else {
$dataZh['category_id'] = $category->id;
// $this->repoZh->store($dataZh);
// }
if($manual==1){
$dataZh['name'] = $data['name_zh'];
}
else{
if (strip_tags($data['name']) == null) {
$data['name'] = 'kosong';
}
$this->repoZh->store($dataZh);
$trans = new GoogleTranslate();
$name = $trans->translate($this->SOURCE, $this->TARGETZH, $data['name']);
$dataZh['name'] = $name;
}
$this->repoZh->update($dataZh, $category);
}
/**
......
......@@ -35,7 +35,9 @@ class CategoryRepository extends Repository
return DataTables::of($data)
->addIndexColumn()
->addColumn('action', function ($row) {
$btn = '<a href="' . url('/webprofile/category/' . $row->id . '/edit') . '" data-toggle="tooltip" data-id="' . $row->id . '" data-original-title="Edit" class="edit btn btn-warning btn-round btn-sm edit">Edit</a>';
$btn = '<a href="'.url('/webprofile/category/'.$row->id.'/edit').'" data-toggle="tooltip" data-id="'.$row->id.'" data-original-title="'.trans('label.editsemuabahasa').'" class="edit btn btn-warning btn-round btn-sm edit">'.trans('label.editsemuabahasa').'</a>';
$btn = $btn . ' <a href="'.url('/webprofile/category/'.$row->id.'/editperbahasa').'" data-toggle="tooltip" data-id="'.$row->id.'" data-original-title="'.trans('label.edittiapbahasa').'" class="edit btn btn-warning btn-round btn-sm edit">'.trans('label.edittiapbahasa').'</a>';
$btn = $btn . ' <a href="javascript:void(0)" data-toggle="tooltip" data-id="' . $row->id . '" data-original-title="Delete" class="btn btn-danger btn-round btn-sm delete">Delete</a>';
......
......@@ -19,4 +19,11 @@ class CategoryRepository extends Repository
public function paginate()
{
}
public function update($data, $post)
{
return $this->model->updateOrCreate([
'category_id' => $post->id,
], $data);
}
}
......@@ -18,4 +18,11 @@ class CategoryRepository extends Repository
public function paginate()
{
}
public function update($data, $post)
{
return $this->model->updateOrCreate([
'category_id' => $post->id,
], $data);
}
}
......@@ -19,4 +19,11 @@ class CategoryRepository extends Repository
public function paginate()
{
}
public function update($data, $post)
{
return $this->model->updateOrCreate([
'category_id' => $post->id,
], $data);
}
}
......@@ -19,4 +19,11 @@ class CategoryRepository extends Repository
public function paginate()
{
}
public function update($data, $post)
{
return $this->model->updateOrCreate([
'category_id' => $post->id,
], $data);
}
}
......@@ -29,13 +29,14 @@
<label class="col-md-2 control-label">Kategori</label>
<div class="col-md-10">
{{ Form::text('name', old('name'), array('class' => 'form-control')) }}
{{ Form::hidden('manual',$manual, array('id'=>'manual')) }}
@if ($errors->has('name'))
<label id="login-error" class="error" for="login">{{$errors->first('name')}}</label>
@endif
</div>
</div>
</div>
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
{{-- <div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
English Language
</div>
<div class="col-md-12">
......@@ -93,7 +94,7 @@
@endif
</div>
</div>
</div>
</div> --}}
<div class="col-md-12">
<div class="form-group" style="padding-top: 10px;">
......
@extends('webprofile.backend.layouts.master')
@section('title')
{{ $title }}
@stop
@section('breadcrumbs')
<li><a href="{{ url('dashboard') }}">Dashboard</a></li>
<li class="active">Ubah Kategori</li>
@stop
@section('content')
{!! Form::model($data, ['route' => ['category.update', $data->id], 'method'=>'patch', 'class'=>'form-horizontal']) !!}
{!! csrf_field() !!}
<!-- page start-->
<div class="row">
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>Ubah</strong> Kategori</h3>
</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('name')) has-error @endif">
<label class="col-md-2 control-label">Kategori</label>
<div class="col-md-10">
{{ Form::text('name', old('name'), array('class' => 'form-control')) }}
@if ($errors->has('name'))
<label id="login-error" class="error" for="login">{{$errors->first('name')}}</label>
@endif
</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 ? $data->rEn->name : null, array('class' => 'form-control', 'required')) }}
@if ($errors->has('name_en'))
<label id="login-error" class="error" for="login">{{$errors->first('name_en')}}</label>
@endif
</div>
</div>
</div>
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
deutsche Sprache
</div>
<div class="col-md-12">
<div class="form-group @if ($errors->has('name_de')) has-error @endif">
<label class="col-md-2 control-label">Kategorie</label>
<div class="col-md-10">
{{ Form::text('name_de', $data->rDe ? $data->rDe->name : null, array('class' => 'form-control', 'required')) }}
@if ($errors->has('name_de'))
<label id="login-error" class="error" for="login">{{$errors->first('name_de')}}</label>
@endif
</div>
</div>
</div>
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
اللغة الألمانية
</div>
<div class="col-md-12">
<div class="form-group @if ($errors->has('name_sa')) has-error @endif">
<label class="col-md-2 control-label">الفئة</label>
<div class="col-md-10">
{{ Form::text('name_sa', $data->rSa ? $data->rSa->name : null, array('class' => 'form-control', 'required')) }}
@if ($errors->has('name_sa'))
<label id="login-error" class="error" for="login">{{$errors->first('name_sa')}}</label>
@endif
</div>
</div>
</div>
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
类别
</div>
<div class="col-md-12">
<div class="form-group @if ($errors->has('name_zh')) has-error @endif">
<label class="col-md-2 control-label">类别</label>
<div class="col-md-10">
{{ Form::text('name_zh', $data->rZh ? $data->rZh->name : null, array('class' => 'form-control', 'required')) }}
@if ($errors->has('name_zh'))
<label id="login-error" class="error" for="login">{{$errors->first('name_zh')}}</label>
@endif
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group" style="padding-top: 10px;">
<label class="col-md-2 control-label">Status</label>
<div class="col-md-10">
<label class="switch">
{{ Form::checkbox('is_active', null, null) }}
<span></span>
</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-footer">
<a href="{{URL::to('webprofile/category')}}" class="btn btn-default pull-right">Batal</a>
<button class="btn btn-info pull-right">Simpan</button>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
<!-- page end-->
@stop
@section('script')
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/bootstrap/bootstrap-datepicker.js') !!}
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/bootstrap/bootstrap-timepicker.min.js') !!}
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/bootstrap/bootstrap-file-input.js') !!}
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/summernote/summernote.js') !!}
@stop
@extends('webprofile.backend.layouts.master')
@section('title')
{{ $title }}
@stop
@section('breadcrumbs')
<li><a href="{{ url('dashboard') }}">Dashboard</a></li>
<li class="active">Ubah Kategori</li>
@stop
@section('content')
{!! Form::model($data, ['route' => ['category.update', $data->id], 'method'=>'patch', 'class'=>'form-horizontal']) !!}
{!! csrf_field() !!}
<!-- page start-->
{{-- <div class="row">
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>Ubah</strong> Kategori</h3>
</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('name')) has-error @endif">
<label class="col-md-2 control-label">Kategori</label>
<div class="col-md-10">
{{ Form::hidden('manual', $manual, array('id'=>'manual')) }}
{{ Form::text('name', old('name'), array('class' => 'form-control')) }}
@if ($errors->has('name'))
<label id="login-error" class="error" for="login">{{$errors->first('name')}}</label>
@endif
</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 ? $data->rEn->name : null, array('class' => 'form-control', 'required')) }}
@if ($errors->has('name_en'))
<label id="login-error" class="error" for="login">{{$errors->first('name_en')}}</label>
@endif
</div>
</div>
</div>
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
deutsche Sprache
</div>
<div class="col-md-12">
<div class="form-group @if ($errors->has('name_de')) has-error @endif">
<label class="col-md-2 control-label">Kategorie</label>
<div class="col-md-10">
{{ Form::text('name_de', $data->rDe ? $data->rDe->name : null, array('class' => 'form-control', 'required')) }}
@if ($errors->has('name_de'))
<label id="login-error" class="error" for="login">{{$errors->first('name_de')}}</label>
@endif
</div>
</div>
</div>
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
اللغة الألمانية
</div>
<div class="col-md-12">
<div class="form-group @if ($errors->has('name_sa')) has-error @endif">
<label class="col-md-2 control-label">الفئة</label>
<div class="col-md-10">
{{ Form::text('name_sa', $data->rSa ? $data->rSa->name : null, array('class' => 'form-control', 'required')) }}
@if ($errors->has('name_sa'))
<label id="login-error" class="error" for="login">{{$errors->first('name_sa')}}</label>
@endif
</div>
</div>
</div>
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
类别
</div>
<div class="col-md-12">
<div class="form-group @if ($errors->has('name_zh')) has-error @endif">
<label class="col-md-2 control-label">类别</label>
<div class="col-md-10">
{{ Form::text('name_zh', $data->rZh ? $data->rZh->name : null, array('class' => 'form-control', 'required')) }}
@if ($errors->has('name_zh'))
<label id="login-error" class="error" for="login">{{$errors->first('name_zh')}}</label>
@endif
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group" style="padding-top: 10px;">
<label class="col-md-2 control-label">Status</label>
<div class="col-md-10">
<label class="switch">
{{ Form::checkbox('is_active', null, null) }}
<span></span>
</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-footer">
<a href="{{URL::to('webprofile/category')}}" class="btn btn-default pull-right">Batal</a>
<button class="btn btn-info pull-right">Simpan</button>
</div>
</div>
</div>
</div> --}}
<div class="tabs">
<ul class="nav nav-tabs" role="tablist">
<li class="active"><a href="#indonesia" role="tab" data-toggle="tab" aria-expanded="true">Indonesia</a></li>
<li class=""><a href="#inggris" role="tab" data-toggle="tab" aria-expanded="false">Inggris</a></li>
<li class=""><a href="#jerman" role="tab" data-toggle="tab" aria-expanded="false">Jerman</a></li>
<li class=""><a href="#arab" role="tab" data-toggle="tab" aria-expanded="false">Arab</a></li>
<li class=""><a href="#cina" role="tab" data-toggle="tab" aria-expanded="false">Cina</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="indonesia">
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
Bahasa Indonesia
</div>
<<div class="col-md-9">
<div class="form-group @if ($errors->has('name')) has-error @endif">
<label class="col-md-2 control-label">Kategori</label>
<div class="col-md-10">
{{ Form::hidden('manual', $manual, array('id'=>'manual')) }}
{{ Form::text('name', old('name'), array('class' => 'form-control')) }}
@if ($errors->has('name'))
<label id="login-error" class="error" for="login">{{$errors->first('name')}}</label>
@endif
</div>
</div>
</div>
</div>
<div class="tab-pane" id="inggris">
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
English Language
</div>
<div class="col-md-9">
<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 ? $data->rEn->name : null, array('class' => 'form-control', 'required')) }}
@if ($errors->has('name_en'))
<label id="login-error" class="error" for="login">{{$errors->first('name_en')}}</label>
@endif
</div>
</div>
</div>
</div>
<div class="tab-pane" id="jerman">
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
Deutsche Sprache
</div>
<div class="col-md-9">
<div class="form-group @if ($errors->has('name_de')) has-error @endif">
<label class="col-md-2 control-label">Kategorie</label>
<div class="col-md-10">
{{ Form::text('name_de', $data->rDe ? $data->rDe->name : null, array('class' => 'form-control', 'required')) }}
@if ($errors->has('name_de'))
<label id="login-error" class="error" for="login">{{$errors->first('name_de')}}</label>
@endif
</div>
</div>
</div>
</div>
<div class="tab-pane" id="arab">
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
اللغة العربية
</div>
<div class="col-md-9">
<div class="form-group @if ($errors->has('name_sa')) has-error @endif">
<label class="col-md-2 control-label">الفئة</label>
<div class="col-md-10">
{{ Form::text('name_sa', $data->rSa ? $data->rSa->name : null, array('class' => 'form-control', 'required')) }}
@if ($errors->has('name_sa'))
<label id="login-error" class="error" for="login">{{$errors->first('name_sa')}}</label>
@endif
</div>
</div>
</div>
</div>
<div class="tab-pane" id="cina">
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
中文
</div>
<div class="col-md-9">
<div class="form-group @if ($errors->has('name_zh')) has-error @endif">
<label class="col-md-2 control-label">类别</label>
<div class="col-md-10">
{{ Form::text('name_zh', $data->rZh ? $data->rZh->name : null, array('class' => 'form-control', 'required')) }}
@if ($errors->has('name_zh'))
<label id="login-error" class="error" for="login">{{$errors->first('name_zh')}}</label>
@endif
</div>
</div>
</div>
</div>
</div>
<div class="col-md-9">
<div class="form-group" style="padding-top: 10px;">
<label class="col-md-2 control-label">Status</label>
<div class="col-md-10">
<label class="switch">
{{ Form::checkbox('is_active', null, null) }}
<span></span>
</label>
</div>
</div>
</div>
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-footer">
<a href="{{URL::to('webprofile/category')}}" class="btn btn-default pull-right">Batal</a>
<button class="btn btn-info pull-right">Simpan</button>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
<!-- page end-->
@stop
@section('script')
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/bootstrap/bootstrap-datepicker.js') !!}
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/bootstrap/bootstrap-timepicker.min.js') !!}
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/bootstrap/bootstrap-file-input.js') !!}
{!! Html::script('https://statik.unesa.ac.id/perpus_konten_statik/admin/js/plugins/summernote/summernote.js') !!}
@stop
<?php
use App\Http\Controllers\Webprofile\Backend\CategoryController;
Route::group(['middleware' => 'auth'], function () {
Route::group(['middleware' => 'role:admin'], function () {
Route::group(['namespace' => 'Webprofile', 'prefix' => 'webprofile'], function () {
......@@ -14,6 +16,7 @@ Route::group(['middleware' => 'auth'], function () {
Route::group(['middleware' => 'role:admin|laman'], function () {
Route::group(['namespace' => 'Webprofile\Backend', 'prefix' => 'webprofile'], function () {
Route::get('category/{id}/editperbahasa', 'CategoryController@editperbahasa');
Route::resource('category', 'CategoryController');
Route::get('posts/{id}/editperbahasa', 'PostController@editperbahasa');
Route::resource('posts', 'PostController');
......@@ -23,6 +26,7 @@ Route::group(['middleware' => 'auth'], function () {
Route::resource('settings', 'SettingController');
Route::resource('sliders', 'SliderController');
Route::resource('gallery', 'GalleryController');
Route::resource('categoriesfile', 'CategoriesFileController');
Route::resource('file', 'FileController');
Route::resource('layouts', 'LayoutController');
......
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