api code global jain
This commit is contained in:
199
app/Http/Controllers/Backend/ViharController.php
Normal file
199
app/Http/Controllers/Backend/ViharController.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Backend;
|
||||
|
||||
use App\Models\Sant;
|
||||
use App\Models\Vihar;
|
||||
use App\Constant\Constant;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Http\Requests\Vihar\StoreViharRequest;
|
||||
use App\Http\Requests\Vihar\UpdateViharRequest;
|
||||
use App\Repositories\Backend\Vihar\ViharService;
|
||||
|
||||
class ViharController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ViharService
|
||||
*/
|
||||
protected $viharService;
|
||||
|
||||
/**
|
||||
* ViharController constructor.
|
||||
* @param ViharService $viharService
|
||||
*/
|
||||
public function __construct(ViharService $viharService)
|
||||
{
|
||||
$this->viharService = $viharService;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is returning the Datatable columns response
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array|object
|
||||
*/
|
||||
public function getViharListing(Request $request, Sant $sant)
|
||||
{
|
||||
$response = [];
|
||||
try {
|
||||
$response = $this->viharService->getForDataTable($request->all(), $sant->id);
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Sant $sant)
|
||||
{
|
||||
try {
|
||||
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
}
|
||||
|
||||
return view('backend.sant.sant-vihar.list', compact('sant'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create(Sant $sant)
|
||||
{
|
||||
try {
|
||||
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
}
|
||||
|
||||
return view('backend.sant.sant-vihar.create', compact('sant'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\StoreViharRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Sant $sant,StoreViharRequest $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->viharService->create($request,$sant->id);
|
||||
|
||||
if ($response) {
|
||||
return redirect(route('admin.sant.vihar.index',compact('sant')))
|
||||
->with('flash_success', __('message.create_vihar_success'));
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
}
|
||||
|
||||
return redirect()->back()->with('flash_error', __('message.create_vihar_error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Vihar $vihar
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Sant $sant,Vihar $vihar)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Vihar $vihar
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Sant $sant,Vihar $vihar)
|
||||
{
|
||||
try {
|
||||
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
}
|
||||
|
||||
return view('backend.sant.sant-vihar.edit', compact('vihar', 'sant'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\UpdateViharRequest $request
|
||||
* @param \App\Models\Vihar $vihar
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateViharRequest $request, Sant $sant, Vihar $vihar)
|
||||
{
|
||||
try {
|
||||
$response = $this->viharService->update($vihar, $request->all(), $sant->id);
|
||||
|
||||
if ($response) {
|
||||
return redirect(route('admin.sant.vihar.index',compact('sant')))
|
||||
->with('flash_success', __('message.update_vihar_success'));
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
}
|
||||
|
||||
return redirect()->back()->with('flash_error', __('message.update_vihar_error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Vihar $vihar
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Sant $sant,Vihar $vihar)
|
||||
{
|
||||
try {
|
||||
|
||||
$response = $vihar->delete();
|
||||
if ($response) {
|
||||
return response()->json(['success' => Constant::STATUS_TRUE, 'message' => __('message.delete_vihar_success')]);
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
}
|
||||
|
||||
return response()->json(['error' => Constant::STATUS_TRUE, 'message' => __('message.delete_vihar_error')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is for the grid checkbox multiple records actions
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function gridRecordsAction(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$actionType = $request->action_type ?? Constant::NULL;
|
||||
$checkedRecords = $request->checked_records ?? [];
|
||||
$updateStatus = $this->viharService->gridActions($actionType, $checkedRecords);
|
||||
|
||||
if ($updateStatus) {
|
||||
return response()->json(['success' => Constant::STATUS_TRUE, 'message' => __('message.update_vihar_success')]);
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
}
|
||||
|
||||
return response()->json(['error' => Constant::STATUS_TRUE, 'message' => __('message.something_went_wrong')]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user