Файловый менеджер - Редактировать - /home/c7lekhnath/silverray.com.au/Modules/Location/app/Http/Controllers/CountryStateController.php
Назад
<?php namespace Modules\Location\app\Http\Controllers; use Str; use App\Enums\RedirectType; use Illuminate\Http\Request; use Illuminate\Http\Response; use App\Traits\RedirectHelperTrait; use App\Http\Controllers\Controller; use Illuminate\Pagination\Paginator; use Illuminate\Http\RedirectResponse; use Modules\Location\app\Models\Country; use Modules\Location\app\Models\CountryState; class CountryStateController extends Controller { use RedirectHelperTrait; /** * Display a listing of the resource. */ public function index(Request $request) { checkAdminHasPermissionAndThrowException('state.view'); $query = CountryState::query(); $query->when($request->filled('keyword'), function ($qa) use ($request) { $qa->where('title', 'like', '%'.$request->keyword.'%'); }); $query->when($request->filled('status'), function ($q) use ($request) { $q->where('status', $request->status); }); $orderBy = $request->filled( 'order_by' ) && $request->order_by == 1 ? 'asc' : 'desc'; if ($request->filled('par-page')) { $countryStates = $request->get('par-page') == 'all' ? $query->orderBy( 'id', $orderBy )->get() : $query->orderBy( 'id', $orderBy )->paginate($request->get('par-page'))->withQueryString(); } else { $countryStates = $query->orderBy( 'id', $orderBy )->paginate()->withQueryString(); } return view('location::countrystate.index', compact('countryStates')); } /** * Show the form for creating a new resource. */ public function create() { checkAdminHasPermissionAndThrowException('state.create'); $countries=Country::all(); return view('location::countrystate.create', compact('countries')); } /** * Store a newly created resource in storage. */ public function store(Request $request): RedirectResponse { checkAdminHasPermissionAndThrowException('state.store'); $rules = [ 'country'=>'required', 'title'=>'required|unique:country_states' ]; $customMessages = [ 'country.required' => trans('Country is required'), 'title.required' => trans('Title is required'), 'title.unique' => trans('Title already exist'), ]; $this->validate($request, $rules, $customMessages); $countryState=new CountryState(); $countryState->country_id=$request->country; $countryState->title=$request->title; $countryState->slug=Str::slug($request->title); $countryState->save(); return $this->redirectWithMessage(RedirectType::CREATE->value, 'admin.country-state.edit', ['country_state' => $countryState->id]); } /** * Show the specified resource. */ public function show($id) { return view('location::show'); } /** * Show the form for editing the specified resource. */ public function edit($id) { checkAdminHasPermissionAndThrowException('state.edit'); $countries=Country::all(); $countryState = CountryState::findOrFail($id); return view('location::countrystate.edit', compact('countries','countryState')); } /** * Update the specified resource in storage. */ public function update(Request $request, $id): RedirectResponse { checkAdminHasPermissionAndThrowException('state.update'); $rules = [ 'country'=>'required', 'title'=>'required|unique:country_states,title,'.$id ]; $customMessages = [ 'country.required' => trans('Country field is required'), 'title.required' => trans('Title is required'), 'title.unique' => trans('Title already exist'), ]; $this->validate($request, $rules, $customMessages); $countryState = CountryState::findOrFail($id); $countryState->country_id=$request->country; $countryState->title=$request->title; $countryState->slug=Str::slug($request->title); $countryState->save(); return $this->redirectWithMessage(RedirectType::UPDATE->value, 'admin.country-state.edit', ['country_state' => $countryState->id]); } /** * Remove the specified resource from storage. */ public function destroy($id) { checkAdminHasPermissionAndThrowException('state.delete'); $countryState = CountryState::findOrFail($id); if ($countryState->cities()->count() > 0) { $notification = trans('You can not delete this state there are multiple city exist under this state.'); $notification=array('messege'=>$notification,'alert-type'=>'error'); return redirect()->back()->with($notification); } $countryState->delete(); return $this->redirectWithMessage(RedirectType::DELETE->value, 'admin.country-state.index'); } public function statusUpdate($id) { checkAdminHasPermissionAndThrowException('state.update'); $countryState = CountryState::find($id); $status = $countryState->status == 1 ? 0 : 1; $countryState->update(['status' => $status]); $notification = __('Updated Successfully'); return response()->json([ 'success' => true, 'message' => $notification, ]); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.20 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка