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