215 lines
6.4 KiB
PHP
215 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Priority;
|
|
use Session;
|
|
use DB;
|
|
|
|
class PrioritiesController 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()
|
|
{
|
|
$languages = DB::table('languages')
|
|
->orderBy('serial_no', 'asc')
|
|
->get();
|
|
$priorities = Priority::orderBy('id', 'desc')->get();
|
|
return view('admin.priorities.index', compact('priorities', 'languages'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$languages = DB::table('languages')
|
|
->orderBy('serial_no', 'asc')
|
|
->get();
|
|
return view('admin.priorities.create', compact('languages'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$languages = DB::table('languages')
|
|
->orderBy('serial_no', 'asc')
|
|
->get();
|
|
$request->session()->put('old_data', $request->all());
|
|
$name=[];
|
|
$error_array=[];
|
|
if(!empty($languages)):
|
|
foreach($languages as $language):
|
|
if(isset($request['name_'.$language->short_name])):
|
|
if($request['name_'.$language->short_name]== ''):
|
|
Session::flash('error_message', 'Priority name for '.$language->name.' ( '.strtoupper($language->short_name).' ) is required.');
|
|
return redirect()->back();
|
|
else:
|
|
$exists_check = Priority::where('name', 'LIKE', '%"'.$language->short_name.'":"'.$request['name_'.$language->short_name].'"%')->first();
|
|
if(isset($exists_check) && !empty($exists_check)):
|
|
Session::flash('error_message', 'Priority name for '.$language->name.' ( '.strtoupper($language->short_name).' ) is already exists.');
|
|
return redirect()->back();
|
|
else:
|
|
$name[$language->short_name]= $request['name_'.$language->short_name];
|
|
endif;
|
|
endif;
|
|
endif;
|
|
endforeach;
|
|
endif;
|
|
$request['name'] = json_encode($name);
|
|
$input = $request->all();
|
|
$saved_data=Priority::create($input);
|
|
if($saved_data)
|
|
{
|
|
$request->session()->forget('old_data');
|
|
Session::flash('success_message', 'Priority has been added successfully');
|
|
return redirect()->route('priorities');
|
|
}
|
|
else
|
|
{
|
|
Session::flash('error_message', 'We are having some problem. Please try later.');
|
|
return redirect()->route('add-priority');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
$priority = Priority::where('id', '=', $id)->first();
|
|
if($priority):
|
|
$languages = DB::table('languages')
|
|
->orderBy('serial_no', 'asc')
|
|
->get();
|
|
return view('admin.priorities.edit', compact('priority', 'languages'));
|
|
else:
|
|
Session::flash('error_message', 'Invalid priority id.');
|
|
return redirect()->route('priorities');
|
|
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);
|
|
$priority = Priority::findOrFail($id);
|
|
$languages = DB::table('languages')
|
|
->orderBy('serial_no', 'asc')
|
|
->get();
|
|
$request->session()->put('old_data', $request->all());
|
|
$name=[];
|
|
$error_array=[];
|
|
if(!empty($languages)):
|
|
foreach($languages as $language):
|
|
if(isset($request['name_'.$language->short_name])):
|
|
if($request['name_'.$language->short_name]== ''):
|
|
Session::flash('error_message', 'Priority name for '.$language->name.' ( '.strtoupper($language->short_name).' ) is required.');
|
|
return redirect()->back();
|
|
else:
|
|
$exists_check = Priority::where('name', 'LIKE', '%"'.$language->short_name.'":"'.$request['name_'.$language->short_name].'"%')->where('id', '<>', $id)->first();
|
|
if(isset($exists_check) && !empty($exists_check)):
|
|
Session::flash('error_message', 'Priority name for '.$language->name.' ( '.strtoupper($language->short_name).' ) is already exists.');
|
|
return redirect()->back();
|
|
else:
|
|
$name[$language->short_name]= $request['name_'.$language->short_name];
|
|
endif;
|
|
endif;
|
|
endif;
|
|
endforeach;
|
|
endif;
|
|
$request['name'] = json_encode($name);
|
|
$input = $request->all();
|
|
$saved_data=$priority->fill($input)->save();
|
|
if($saved_data):
|
|
$request->session()->forget('old_data');
|
|
Session::flash('success_message', 'Priority has been updated successfully');
|
|
return redirect()->route('priorities');
|
|
else:
|
|
Session::flash('error_message', 'We are having some problem. Please try later.');
|
|
return redirect()->route('edit-priority');
|
|
endif;
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
$id=base64_decode($id);
|
|
$delete_priority = Priority::where('id', $id)->delete();
|
|
if($delete_priority):
|
|
Session::flash('success_message', 'Priority has been deleted successfully');
|
|
return redirect()->route('priorities');
|
|
else:
|
|
Session::flash('error_message', 'We are having some problem. Please try later.');
|
|
return redirect()->route('priorities');
|
|
endif;
|
|
}
|
|
public function statusupdate($id)
|
|
{
|
|
$id=base64_decode($id);
|
|
$find_priority = Priority::findOrFail($id);
|
|
if($find_priority->status==1)
|
|
$status=0;
|
|
else
|
|
$status=1;
|
|
$input=[
|
|
'status'=>$status
|
|
];
|
|
$saved_data=$find_priority->fill($input)->save();
|
|
if($saved_data):
|
|
Session::flash('success_message', 'Priority has been updated successfully');
|
|
return redirect()->route('priorities');
|
|
else:
|
|
Session::flash('error_message', 'We are having some problem. Please try later.');
|
|
return redirect()->route('priorities');
|
|
endif;
|
|
}
|
|
}
|