Файловый менеджер - Редактировать - /home/clickysoft/public_html/travel-guru.clickysoft.net/app/Repositories/DestinationRepository.php
Назад
<?php namespace App\Repositories; use App\Interfaces\DestinationRepositoryInterface; use App\Models\Destination; use Yajra\DataTables\Facades\DataTables; class DestinationRepository implements DestinationRepositoryInterface { public function getAllDestinations() { return Destination::where('status', true)->get(); } public function getDestination($id) { return Destination::findOrFail($id); } public function getDetailBySlug($slug) { return Destination::where('slug', $slug) ->with(['countries']) ->with(['users' => 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 destination $destination = Destination::create($req->all()); // Handle the featured image if ($req->hasFile('featured_image')) { $destination->addMedia($req->file('featured_image')) ->toMediaCollection('featured_image'); } // Attach selected countries to the destination if ($req->has('selected_countries')) { $countryIds = explode(',', $req->input('selected_countries')); $destination->countries()->sync($countryIds); } return $destination; } public function update($id, $req) { $destination = Destination::where('id', $id)->first(); if (!empty($destination)) { $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]); } $destination->update($req->all()); if ($req->hasFile('featured_image')) { $destination->clearMediaCollection('featured_image'); $destination->addMedia($req->file('featured_image')) ->toMediaCollection('featured_image'); } if ($req->has('selected_countries')) { $countryIds = explode(',', $req->input('selected_countries')); $destination->countries()->sync($countryIds); } return redirect()->route('destinations')->with('success_msg', 'Destination successfully updated.'); } return redirect()->back()->withInput()->with('error_msg', 'Destination not found.'); } public function getDataTable() { $query = Destination::query(); return Datatables::of($query) ->filter(function ($instance) { $search = request('search')['value']; if (!empty($search)) { $instance->where(function ($w) use ($search) { $w->orWhere('title', 'LIKE', "%$search%"); if (strtolower($search) === "active") { $w->orWhere('status', 1); } elseif (strtolower($search) === "inactive") { $w->orWhere('status', 0); } }); } }) ->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('destination.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('destination.update', $obj->id) . '">Edit</a> </div>'; // <button class="btn btn-danger btn-sm redirect-btn" onclick="deleteData(`'. route('destination.delete', $obj->id).'`)">Delete</button> return $buttons; })->rawColumns(['status', 'action'])->make(true); } public function changeStatus($destinationId) { $msg = 'Something went wrong.'; $code = 400; $destination = $this->getDestination($destinationId); if (!empty($destination)) { $destination->update([ 'status' => !$destination->status ]); $msg = "Destination status successfully changed."; $code = 200; } return response()->json(['msg' => $msg], $code); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка