219 lines
5.7 KiB
PHP
219 lines
5.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Backend;
|
||
|
|
|
||
|
|
use Exception;
|
||
|
|
use App\Models\Dharma;
|
||
|
|
use App\Constant\Constant;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Http\JsonResponse;
|
||
|
|
use Illuminate\Support\Facades\Log;
|
||
|
|
use App\Http\Controllers\BaseController;
|
||
|
|
use App\Http\Requests\Dharma\StoreDharmaRequest;
|
||
|
|
use App\Http\Requests\Dharma\UpdateDharmaRequest;
|
||
|
|
use App\Repositories\Backend\Dharma\DharmaService;
|
||
|
|
|
||
|
|
class DharmaController extends BaseController
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @var DharmaService
|
||
|
|
*/
|
||
|
|
protected $dharmaService;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* DharmaController constructor.
|
||
|
|
* @param DharmaService $dharmaService
|
||
|
|
*/
|
||
|
|
public function __construct(DharmaService $dharmaService)
|
||
|
|
{
|
||
|
|
$this->dharmaService = $dharmaService;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* This function is returning the Datatable columns response
|
||
|
|
*
|
||
|
|
* @param Request $request
|
||
|
|
* @return array|object
|
||
|
|
*/
|
||
|
|
public function getDharmaListing(Request $request)
|
||
|
|
{
|
||
|
|
$response = [];
|
||
|
|
try {
|
||
|
|
$response = $this->dharmaService->getForDataTable($request->all());
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return $response;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display a listing of the resource.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function index()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return view('backend.dharma.list');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for creating a new resource.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function create()
|
||
|
|
{
|
||
|
|
//
|
||
|
|
try {
|
||
|
|
//
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
return view('backend.dharma.create');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Store a newly created resource in storage.
|
||
|
|
*
|
||
|
|
* @param \App\Http\Requests\StoreDharmaRequest $request
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function store(StoreDharmaRequest $request)
|
||
|
|
{
|
||
|
|
//
|
||
|
|
try {
|
||
|
|
$response = $this->dharmaService->create($request->all());
|
||
|
|
if ($response) {
|
||
|
|
return redirect(route('admin.dharma.index'))
|
||
|
|
->with('flash_success', __('message.create_dharma_success'));
|
||
|
|
}
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return redirect()->back()->with('flash_error', __('message.create_dharma_error'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display the specified resource.
|
||
|
|
*
|
||
|
|
* @param \App\Models\Dharma $dharma
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function show(Dharma $dharma)
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for editing the specified resource.
|
||
|
|
*
|
||
|
|
* @param \App\Models\Dharma $dharma
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function edit(Dharma $dharma)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
//
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return view('backend.dharma.edit', compact('dharma'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Update the specified resource in storage.
|
||
|
|
*
|
||
|
|
* @param \App\Http\Requests\UpdateDharmaRequest $request
|
||
|
|
* @param \App\Models\Dharma $dharma
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function update(UpdateDharmaRequest $request, Dharma $dharma)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$response = $this->dharmaService->update($dharma, $request->all());
|
||
|
|
|
||
|
|
if ($response) {
|
||
|
|
return redirect(route('admin.dharma.index'))
|
||
|
|
->with('flash_success', __('message.update_dharma_success'));
|
||
|
|
}
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return redirect()->back()->with('flash_error', __('message.update_dharma_error'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Remove the specified resource from storage.
|
||
|
|
*
|
||
|
|
* @param \App\Models\Dharma $dharma
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function destroy(Dharma $dharma)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
|
||
|
|
$response = $dharma->delete();
|
||
|
|
if ($response) {
|
||
|
|
return response()->json(['success' => Constant::STATUS_TRUE, 'message' => __('message.delete_dharma_success')]);
|
||
|
|
}
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return response()->json(['error' => Constant::STATUS_TRUE, 'message' => __('message.delete_dharma_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->dharmaService->gridActions($actionType, $checkedRecords);
|
||
|
|
|
||
|
|
if ($updateStatus) {
|
||
|
|
return response()->json(['success' => Constant::STATUS_TRUE, 'message' => __('message.update_dharm_success')]);
|
||
|
|
}
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return response()->json(['error' => Constant::STATUS_TRUE, 'message' => __('message.something_went_wrong')]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get Sampraday of related dharma.
|
||
|
|
*
|
||
|
|
* @param Request $request
|
||
|
|
* @return JsonResponse
|
||
|
|
*/
|
||
|
|
public function getSampradayByDharma(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$sampraday = $this->dharmaService->getSampradayByDharma($request->all());
|
||
|
|
|
||
|
|
return response()->json([
|
||
|
|
'sampradaies' => $sampraday
|
||
|
|
]);
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|