Файловый менеджер - Редактировать - /home/clickysoft/public_html/travel-guru.clickysoft.net/app/Repositories/CountryRepository.php
Назад
<?php namespace App\Repositories; use App\Interfaces\CountryRepositoryInterface; use App\Models\Country; use Yajra\DataTables\Facades\DataTables; class CountryRepository implements CountryRepositoryInterface { public function getAllCountries() { return Country::where('id', 1)->get(); } public function getCountry($id) { return Country::findOrFail($id); } public function getDetailBySlug($slug) { return Country::where('slug', $slug) ->with(['countryUsers' => function ($query) { $query->withAvg('userReviews', 'rating') ->where('is_active', true) ->whereNotNull('email_verified_at') ->orderByDesc('user_reviews_avg_rating'); }]) ->firstOrFail(); } public function create($req) { // Process meta keywords $metaKeywordsJson = $req->input('meta_keywords'); $metaKeywordsArray = json_decode($metaKeywordsJson, true); $metaKeywords = []; if (is_array($metaKeywordsArray)) { foreach ($metaKeywordsArray as $item) { if (isset($item['value'])) { $metaKeywords[] = $item['value']; } } } $metaKeywordsString = implode(', ', $metaKeywords); $req->merge(['meta_keywords' => $metaKeywordsString]); // Process SEO data $seoData = []; if ($req->has('seo_name')) { foreach ($req->input('seo_name') as $key => $type) { $name = $req->input('seo_name')[$key] ?? ''; $value = $req->input('seo_value')[$key] ?? ''; $seoData[] = [ 'seo_type' => $type, 'seo_name' => $name, 'seo_value' => $value, ]; } $seoData = json_encode($seoData); $req->merge(['seo' => $seoData]); } // Create the country $country = Country::create($req->all()); // if ($req->hasFile('featured_image')) { // $country->addMedia($req->file('featured_image')) // ->toMediaCollection('featured_image'); // } $country->destinations()->sync($req->input('destination')); return $country; } public function update($id, $req) { $country = Country::where('id', $id)->first(); if (!empty($country)) { $metaKeywordsJson = $req->input('meta_keywords'); $metaKeywordsArray = json_decode($metaKeywordsJson, true); $metaKeywords = []; if (is_array($metaKeywordsArray)) { foreach ($metaKeywordsArray as $item) { if (isset($item['value'])) { $metaKeywords[] = $item['value']; } } } $metaKeywordsString = implode(', ', $metaKeywords); $req->merge(['meta_keywords' => $metaKeywordsString]); $seoData = []; if ($req->has('seo_name')) { foreach ($req->input('seo_name') as $key => $type) { $name = $req->input('seo_name')[$key] ?? ''; $value = $req->input('seo_value')[$key] ?? ''; $seoData[] = [ 'seo_type' => $type, 'seo_name' => $name, 'seo_value' => $value, ]; } $seoData = json_encode($seoData); $req->merge(['seo' => $seoData]); } $country->update($req->all()); // if ($req->hasFile('featured_image')) { // $country->clearMediaCollection('featured_image'); // $country->addMedia($req->file('featured_image')) // ->toMediaCollection('featured_image'); // } $country->destinations()->sync($req->input('destination')); return redirect()->route('countries')->with('success_msg', 'Country successfully updated.'); } return redirect()->back()->withInput()->with('error_msg', 'Country not found.'); } public function getDataTable() { $query = Country::query(); return Datatables::of($query) ->filter(function ($instance) { $search = request('search')['value']; if (!empty($search)) { $instance->where(function ($w) use ($search) { $w->orWhere('name', 'LIKE', "%$search%"); $w->orWhereHas('destinations', function ($query) use ($search) { $query->where('title', 'LIKE', "%$search%"); }); if (strtolower($search) === "active") { $w->orWhere('status', 1); } elseif (strtolower($search) === "inactive") { $w->orWhere('status', 0); } }); } }) ->addColumn('title', function ($country) { return $country->destinations->pluck('title')->implode(', '); }) ->editColumn('status', function ($obj) { $isChecked = ""; if ($obj->status) { $isChecked = "checked"; } return '<label class="switch switch-success"> <input type="checkbox" class="switch-input" ' . $isChecked . ' onclick="changeStatus(`' . route('country.change.status', $obj->id) . '`)" /> <span class="switch-toggle-slider"> <span class="switch-on"> <i class="bx bx-check"></i> </span> <span class="switch-off"> <i class="bx bx-x"></i> </span> </span> </label>'; }) ->addColumn('action', function ($obj) { $buttons = '<div class="btn-group"> <a class="btn btn-success btn-sm redirect-btn" href="' . route('country.update', $obj->id) . '">Edit</a> <button class="btn btn-danger btn-sm redirect-btn" onclick="deleteData(`'. route('country.delete', $obj->id).'`)">Delete</button> </div>'; return $buttons; })->rawColumns(['status','action'])->make(true); } public function changeStatus($countryId) { $msg = 'Something went wrong.'; $code = 400; $country = $this->getCountry($countryId); if (!empty($country)) { $country->update([ 'status' => !$country->status ]); $msg = "Country status successfully changed."; $code = 200; } return response()->json(['msg' => $msg], $code); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка