![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/dceprojects.corals.io/Corals/modules/ProjectPlan/Http/Controllers/ |
<?php namespace Corals\Modules\ProjectPlan\Http\Controllers; use Corals\Foundation\Http\Controllers\BaseController; use Corals\Modules\ProjectPlan\DataTables\HotelsDataTable; use Corals\Modules\ProjectPlan\Http\Requests\HotelRequest; use Corals\Modules\ProjectPlan\Models\Hotel; use Corals\Modules\ProjectPlan\Services\HotelService; use Exception; use Illuminate\Contracts\View\Factory; use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Routing\Redirector; use Illuminate\Validation\ValidationException; use Illuminate\View\View; class HotelsController extends BaseController { protected $hotelService; public function __construct(HotelService $hotelService) { $this->hotelService = $hotelService; $this->resource_url = config('projectPlan.models.hotel.resource_url'); $this->resource_model = new Hotel(); $this->title = trans('ProjectPlan::module.hotel.title'); $this->title_singular = trans('ProjectPlan::module.hotel.title_singular'); parent::__construct(); } /** * @param HotelRequest $request * @param HotelsDataTable $dataTable * @return mixed */ public function index(HotelRequest $request, HotelsDataTable $dataTable) { return $dataTable->render('ProjectPlan::hotels.index'); } /** * @param HotelRequest $request * @return Factory|View */ public function create(HotelRequest $request) { $hotel = new Hotel(); $this->setViewSharedData([ 'title_singular' => trans('Corals::labels.create_title', ['title' => $this->title_singular]) ]); return view('ProjectPlan::hotels.create_edit')->with(compact('hotel')); } /** * @param HotelRequest $request * @return array * @throws ValidationException */ public function store(HotelRequest $request) { try { $hotel = $this->hotelService->store($request, Hotel::class); logger($request->get('no-redirect')); if ($request->get('no-redirect')) { return [ 'target' => $request->get('target'), 'hotel' => $hotel ]; } flash(trans('Corals::messages.success.created', ['item' => $this->title_singular]))->success(); } catch (ValidationException $exception) { throw $exception; } catch (Exception $exception) { log_exception($exception, Hotel::class, 'store'); } return redirectTo($this->resource_url); } /** * @param HotelRequest $request * @param Hotel $hotel * @return Factory|View */ public function show(HotelRequest $request, Hotel $hotel) { $this->setViewSharedData([ 'title_singular' => trans('Corals::labels.show_title', ['title' => $hotel->getIdentifier()]), 'showModel' => $hotel, ]); return view('ProjectPlan::hotels.show')->with(compact('hotel')); } /** * @param HotelRequest $request * @param Hotel $hotel * @return Factory|View */ public function edit(HotelRequest $request, Hotel $hotel) { $this->setViewSharedData([ 'title_singular' => trans('Corals::labels.update_title', ['title' => $hotel->getIdentifier()]) ]); return view('ProjectPlan::hotels.create_edit', compact('hotel')); } /** * @param HotelRequest $request * @param Hotel $hotel * @return RedirectResponse|Redirector * @throws ValidationException */ public function update(HotelRequest $request, Hotel $hotel) { try { $this->hotelService->update($request, $hotel); flash(trans('Corals::messages.success.updated', ['item' => $this->title_singular]))->success(); } catch (ValidationException $exception) { throw $exception; } catch (Exception $exception) { log_exception($exception, Hotel::class, 'update'); } return redirectTo($hotel->getShowURL()); } /** * @param HotelRequest $request * @param Hotel $hotel * @return JsonResponse */ public function destroy(HotelRequest $request, Hotel $hotel) { try { $this->hotelService->destroy($request, $hotel); $message = [ 'level' => 'success', 'message' => trans('Corals::messages.success.deleted', ['item' => $this->title_singular]) ]; } catch (Exception $exception) { log_exception($exception, Hotel::class, 'destroy'); $message = ['level' => 'error', 'message' => $exception->getMessage()]; } return response()->json($message); } public function getHotelForm(HotelRequest $request): string { $hotel = new Hotel(); $isModal = true; $this->setViewSharedData([ 'title_singular' => trans('Corals::labels.create_title', ['title' => $this->title_singular]) ]); $target = $request->get('target'); return view('ProjectPlan::hotels.partials.hotels_form_partial', compact('hotel', 'isModal', 'target')) ->render(); } }