211 lines
6.0 KiB
PHP
211 lines
6.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Admin;
|
||
|
|
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Translation;
|
||
|
|
use App\Setting;
|
||
|
|
use Session;
|
||
|
|
use DB;
|
||
|
|
|
||
|
|
class TranslationsController extends Controller
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Create a new controller instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
$this->middleware('auth:admin');
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Display a listing of the resource.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function index()
|
||
|
|
{
|
||
|
|
$setting = Setting::first();
|
||
|
|
$languages = DB::table('languages')
|
||
|
|
->where('status', '1')
|
||
|
|
->where('id', '<>', $setting->default_language)
|
||
|
|
->orderBy('serial_no', 'asc')
|
||
|
|
->get();
|
||
|
|
$translations = DB::table('translations')
|
||
|
|
->orderBy('id', 'desc')
|
||
|
|
->get();
|
||
|
|
return view('admin.translations.index', compact('translations', 'languages'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for creating a new resource.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function create()
|
||
|
|
{
|
||
|
|
$setting = Setting::first();
|
||
|
|
$languages = DB::table('languages')
|
||
|
|
->where('id', '<>', $setting->default_language)
|
||
|
|
->orderBy('serial_no', 'asc')
|
||
|
|
->get();
|
||
|
|
$default_language = DB::table('languages')
|
||
|
|
->where('id', '=', $setting->default_language)
|
||
|
|
->first();
|
||
|
|
return view('admin.translations.create', compact('languages', 'default_language'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Store a newly created resource in storage.
|
||
|
|
*
|
||
|
|
* @param \Illuminate\Http\Request $request
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function store(Request $request)
|
||
|
|
{
|
||
|
|
$setting = Setting::first();
|
||
|
|
$languages = DB::table('languages')
|
||
|
|
->where('id', '<>', $setting->default_language)
|
||
|
|
->orderBy('serial_no', 'asc')
|
||
|
|
->get();
|
||
|
|
$validatedData = $this->validate($request, [
|
||
|
|
'primary_text' => 'required|unique:translations,primary_text',
|
||
|
|
]);
|
||
|
|
$translation_text=[];
|
||
|
|
$input = $request->all();
|
||
|
|
if(!empty($languages)):
|
||
|
|
foreach($languages as $language):
|
||
|
|
$translation_text[$language->short_name]= $input['translation_text_'.$language->short_name];
|
||
|
|
endforeach;
|
||
|
|
endif;
|
||
|
|
$input['translation_text'] = json_encode($translation_text);
|
||
|
|
$saved_data=Translation::create($input);
|
||
|
|
if($saved_data)
|
||
|
|
{
|
||
|
|
Session::flash('success_message', 'Translation Text has been added successfully');
|
||
|
|
return redirect()->route('translations');
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
Session::flash('error_message', 'We are having some problem. Please try later.');
|
||
|
|
return redirect()->route('add-translation');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display the specified resource.
|
||
|
|
*
|
||
|
|
* @param int $id
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function show($id)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for editing the specified resource.
|
||
|
|
*
|
||
|
|
* @param int $id
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function edit($id)
|
||
|
|
{
|
||
|
|
$id=base64_decode($id);
|
||
|
|
$translation = Translation::where('id', '=', $id)->first();
|
||
|
|
$setting = Setting::first();
|
||
|
|
$languages = DB::table('languages')
|
||
|
|
->where('status', '1')
|
||
|
|
->where('id', '<>', $setting->default_language)
|
||
|
|
->orderBy('serial_no', 'asc')
|
||
|
|
->get();
|
||
|
|
$default_language = DB::table('languages')
|
||
|
|
->where('id', '=', $setting->default_language)
|
||
|
|
->first();
|
||
|
|
if($translation):
|
||
|
|
return view('admin.translations.edit', compact('translation','languages', 'default_language'));
|
||
|
|
else:
|
||
|
|
Session::flash('error_message', 'Invalid translation id.');
|
||
|
|
return redirect()->route('translations');
|
||
|
|
endif;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Update the specified resource in storage.
|
||
|
|
*
|
||
|
|
* @param \Illuminate\Http\Request $request
|
||
|
|
* @param int $id
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function update(Request $request, $id)
|
||
|
|
{
|
||
|
|
$id=base64_decode($id);
|
||
|
|
$translation = Translation::findOrFail($id);
|
||
|
|
$setting = Setting::first();
|
||
|
|
$languages = DB::table('languages')
|
||
|
|
->where('id', '<>', $setting->default_language)
|
||
|
|
->orderBy('serial_no', 'asc')
|
||
|
|
->get();
|
||
|
|
$validatedData = $this->validate($request, [
|
||
|
|
'primary_text' => 'required|unique:translations,primary_text,'.$id,
|
||
|
|
]);
|
||
|
|
$translation_text=[];
|
||
|
|
$input = $request->all();
|
||
|
|
if(!empty($languages)):
|
||
|
|
foreach($languages as $language):
|
||
|
|
$translation_text[$language->short_name]= $input['translation_text_'.$language->short_name];
|
||
|
|
endforeach;
|
||
|
|
endif;
|
||
|
|
$input['translation_text'] = json_encode($translation_text);
|
||
|
|
$saved_data=$translation->fill($input)->save();
|
||
|
|
if($saved_data):
|
||
|
|
Session::flash('success_message', 'Translation has been updated successfully');
|
||
|
|
return redirect()->route('translations');
|
||
|
|
else:
|
||
|
|
Session::flash('error_message', 'We are having some problem. Please try later.');
|
||
|
|
return redirect()->route('edit-translation');
|
||
|
|
endif;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Remove the specified resource from storage.
|
||
|
|
*
|
||
|
|
* @param int $id
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function destroy($id)
|
||
|
|
{
|
||
|
|
$id=base64_decode($id);
|
||
|
|
$translation = Translation::findOrFail($id);
|
||
|
|
$delete_translation = $translation->delete();
|
||
|
|
if($delete_translation):
|
||
|
|
Session::flash('success_message', 'Translation has been deleted successfully');
|
||
|
|
return redirect()->route('translations');
|
||
|
|
else:
|
||
|
|
Session::flash('error_message', 'We are having some problem. Please try later.');
|
||
|
|
return redirect()->route('translations');
|
||
|
|
endif;
|
||
|
|
}
|
||
|
|
public function statusupdate($id)
|
||
|
|
{
|
||
|
|
$id=base64_decode($id);
|
||
|
|
$find_translation = Translation::findOrFail($id);
|
||
|
|
if($find_translation->status==1)
|
||
|
|
$status=0;
|
||
|
|
else
|
||
|
|
$status=1;
|
||
|
|
$input=[
|
||
|
|
'status'=>$status
|
||
|
|
];
|
||
|
|
$saved_data=$find_translation->fill($input)->save();
|
||
|
|
if($saved_data):
|
||
|
|
Session::flash('success_message', 'Translation has been updated successfully');
|
||
|
|
return redirect()->route('translations');
|
||
|
|
else:
|
||
|
|
Session::flash('error_message', 'We are having some problem. Please try later.');
|
||
|
|
return redirect()->route('translations');
|
||
|
|
endif;
|
||
|
|
}
|
||
|
|
}
|