220 lines
6.2 KiB
PHP
220 lines
6.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Backend;
|
||
|
|
|
||
|
|
use Exception;
|
||
|
|
use App\Models\Sampraday;
|
||
|
|
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\Sampraday\StoreSampradayRequest;
|
||
|
|
use App\Http\Requests\Sampraday\UpdateSampradayRequest;
|
||
|
|
use App\Models\Dharma;
|
||
|
|
use App\Models\Sant;
|
||
|
|
use App\Repositories\Backend\Sampraday\SampradayService;
|
||
|
|
|
||
|
|
class SampradayController extends BaseController
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @var SampradayService
|
||
|
|
*/
|
||
|
|
protected $sampradayService;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* SampradayController constructor.
|
||
|
|
* @param SampradayService $sampradayService
|
||
|
|
*/
|
||
|
|
public function __construct(SampradayService $sampradayService)
|
||
|
|
{
|
||
|
|
$this->sampradayService = $sampradayService;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* This function is returning the Datatable columns response
|
||
|
|
*
|
||
|
|
* @param Request $request
|
||
|
|
* @return array|object
|
||
|
|
*/
|
||
|
|
public function getSampradayListing(Request $request)
|
||
|
|
{
|
||
|
|
$response = [];
|
||
|
|
try {
|
||
|
|
$response = $this->sampradayService->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.sampraday.list');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for creating a new resource.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function create()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$sants = Sant::pluck('name', 'id');
|
||
|
|
$dharma = Dharma::pluck('name', 'id');
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
return view('backend.sampraday.create', compact('sants', 'dharma'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Store a newly created resource in storage.
|
||
|
|
*
|
||
|
|
* @param \App\Http\Requests\StoreSampradayRequest $request
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function store(StoreSampradayRequest $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$response = $this->sampradayService->create($request->all());
|
||
|
|
if ($response) {
|
||
|
|
return redirect(route('admin.sampraday.index'))
|
||
|
|
->with('flash_success', __('message.create_sampraday_success'));
|
||
|
|
}
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return redirect()->back()->with('flash_error', __('message.create_sampraday_error'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display the specified resource.
|
||
|
|
*
|
||
|
|
* @param \App\Models\Sampraday $sampraday
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function show(Sampraday $sampraday)
|
||
|
|
{
|
||
|
|
//
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for editing the specified resource.
|
||
|
|
*
|
||
|
|
* @param \App\Models\Sampraday $sampraday
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function edit(Sampraday $sampraday)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$sants = Sant::pluck('name', 'id');
|
||
|
|
$dharma = Dharma::pluck('name', 'id');
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return view('backend.sampraday.edit', compact('sampraday', 'sants', 'dharma'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Update the specified resource in storage.
|
||
|
|
*
|
||
|
|
* @param \App\Http\Requests\UpdateSampradayRequest $request
|
||
|
|
* @param \App\Models\Sampraday $sampraday
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function update(UpdateSampradayRequest $request, Sampraday $sampraday)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$response = $this->sampradayService->update($sampraday, $request->all());
|
||
|
|
|
||
|
|
if ($response) {
|
||
|
|
return redirect(route('admin.sampraday.index'))
|
||
|
|
->with('flash_success', __('message.update_sampraday_success'));
|
||
|
|
}
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return redirect()->back()->with('flash_error', __('message.update_sampraday_error'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Remove the specified resource from storage.
|
||
|
|
*
|
||
|
|
* @param \App\Models\Sampraday $sampraday
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function destroy(Sampraday $sampraday)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
|
||
|
|
$response = $sampraday->delete();
|
||
|
|
if ($response) {
|
||
|
|
return response()->json(['success' => Constant::STATUS_TRUE, 'message' => __('message.delete_sampraday_success')]);
|
||
|
|
}
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return response()->json(['error' => Constant::STATUS_TRUE, 'message' => __('message.delete_sampraday_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->sampradayService->gridActions($actionType, $checkedRecords);
|
||
|
|
|
||
|
|
if ($updateStatus) {
|
||
|
|
return response()->json(['success' => Constant::STATUS_TRUE, 'message' => __('message.update_sampraday_success')]);
|
||
|
|
}
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return response()->json(['error' => Constant::STATUS_TRUE, 'message' => __('message.something_went_wrong')]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get Gachadhi Pati of related dharma.
|
||
|
|
*
|
||
|
|
* @param Request $request
|
||
|
|
* @return JsonResponse
|
||
|
|
*/
|
||
|
|
public function getGachadhiPatiByDharma(Request $request)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$gachadhiPaties = $this->sampradayService->getGachadhiPatiByDharma($request->all());
|
||
|
|
|
||
|
|
return response()->json([
|
||
|
|
'gachadhi_paties' => $gachadhiPaties
|
||
|
|
]);
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|