api code global jain
This commit is contained in:
116
app/Http/Controllers/Backend/HospitalController.php
Normal file
116
app/Http/Controllers/Backend/HospitalController.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Backend;
|
||||
|
||||
use App\Constant\Constant;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Hospital\HospitalStoreRequest;
|
||||
use App\Models\Hospital;
|
||||
use App\Repositories\Backend\Hospital\HospitalService;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HospitalController extends Controller
|
||||
{
|
||||
public function __construct(protected HospitalService $hospitalService)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
return view('backend.hospital.list');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('backend.hospital.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HospitalStoreRequest $request
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function store(HospitalStoreRequest $request): RedirectResponse
|
||||
{
|
||||
$response = $this->hospitalService->storeHospital($request);
|
||||
|
||||
if ($response['status']) {
|
||||
return redirect()->route('admin.hospitals.index')
|
||||
->with('flash_success', __('message.create_hospital_success'));
|
||||
}
|
||||
|
||||
return redirect()->back()->with('flash_error', __('message.create_hospital_error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return View
|
||||
*/
|
||||
public function edit($id): View
|
||||
{
|
||||
$hospital = $this->hospitalService->find($id);
|
||||
return view('backend.hospital.edit', compact('hospital'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
$response = $this->hospitalService->updateHospital($request, $id);
|
||||
|
||||
if ($response['status']) {
|
||||
return redirect()->route('admin.hospitals.index')
|
||||
->with('flash_success', __('message.update_hospital_success'));
|
||||
}
|
||||
|
||||
return redirect()->back()->with('flash_error', __('message.update_hospital_error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function destroy($id): JsonResponse
|
||||
{
|
||||
if ($this->hospitalService->find($id)->delete()) {
|
||||
return response()->json([
|
||||
'success' => Constant::STATUS_TRUE,
|
||||
'message' => __('message.delete_hospital_success')
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => Constant::STATUS_TRUE,
|
||||
'message' => __('message.delete_hospital_error')
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return object
|
||||
* @throws Exception
|
||||
*/
|
||||
public function listing(Request $request): object
|
||||
{
|
||||
return $this->hospitalService->getListing($request);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user