Linux ip-172-31-33-47 5.4.0-1045-aws #47~18.04.1-Ubuntu SMP Tue Apr 13 15:58:14 UTC 2021 x86_64
Apache/2.4.29 (Ubuntu)
: 172.31.33.47 | : 3.144.80.91
Cant Read [ /etc/named.conf ]
7.4.20
www-data
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
var /
www /
html /
stage /
app /
Http /
Controllers /
API /
[ HOME SHELL ]
Name
Size
Permission
Action
FoodController.php
6.27
KB
-rw-rw-r--
NewPlaceController.php
9.01
KB
-rw-rw-r--
PlaceController.php
31.89
KB
-rw-rw-r--
ReviewsController.php
5.32
KB
-rw-rw-r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : PlaceController.php
<?php namespace App\Http\Controllers\API; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Auth; use App\Http\Controllers\Controller; use App\Place; use App\Foods; use App\Http\Services\PostImageUploader; use App\Jobs\ProcessImage; use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Cache; class PlaceController extends Controller { private $db; /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $places = Place::simplePaginate(15); return response()->json($places->toArray()); } private function getMongoDB() { if (is_null($this->db)) { $this->db = DB::getMongoDB(); } return $this->db; } public function results(Request $request) { $term = $request->query->get('q'); $db = $this->getMongoDB(); $places = $db->places->aggregate([ ['$match' => ['name' => ['$regex' => "$term", '$options' => 'i']]], ['$project' => ['_id' => 0, 'slug' => 1, 'address' => 1, 'phones' => 1, 'image' => 1, 'name' => 1, 'delivery' => 1, 'takeaway' => 1]] ]); return response()->json($places->toArray()); } /** * Get Place details * * @param string $slug Place slug **/ public function show(string $slug) { $db = $this->getMongoDB(); // return response()->json(['hey' => $db]); $place = $db->places->aggregate([['$match' => ['slug' => $slug]], ['$project' => [ '_id' => 0, 'name' => 1, 'address' => 1, 'phones' => 1, 'coords' => '$location.coordinates', 'opening' => 1, 'closing' => 1, 'delivery' => 1, 'image' => 1, 'slug' => 1, 'type' => 1, 'avg_rate' => 1, 'category' => 1 ]]] )->toArray()[0]; if($place) { $place['food'] = $db->fooding->aggregate([['$match' => ['place_slug' => $slug]], [ '$project' => [ '_id' => ['$toString' => '$_id'], 'name' => 1, 'description' => 1, 'category' => 1, 'price' => 1, 'avg_rate' => 1, 'img' => 1 ]] ])->toArray(); }else { abort(404, 'Place not found'); } $id = Session::get('search_id'); if($id){ $place_log = [ 'name' => $place['name'], 'slug' => $place['slug'], 'id' => $id ]; $places_file = storage_path(sprintf('app/places_result/places/%s.json', $id)); try { $fh_places = fopen($places_file, "w"); if($fh_places) { fwrite($fh_places, json_encode($place_log) . PHP_EOL); } fclose($fh_places); } catch (\Exception $e) { //throw $th; } } // $pipeline = [ // ['$match' => ['slug' => $slug]], // ['$lookup' => [ // 'from' => 'fooding', // 'let' => ['id' => '$slug'], // 'pipeline' => [ // ['$match' => [ // '$expr' => [ // '$eq' => ['$place_slug', '$$id'] // ] // ]], // ['$project' => [ // '_id' => ['$toString' => '$_id'], // 'name' => 1, // 'description' => 1, // 'category' => 1, // 'price' => 1, // 'rating' => ['$avg' => '$rating.rate'] // ]] // ], // 'as' => 'food' // ]], // [ // '$project' => [ // '_id' => 0, // 'name' => 1, // 'address' => 1, // 'phones' => 1, // 'coords' => '$location.coordinates', // 'opening' => 1, // 'closing' => 1, // 'delivery' => 1, // 'image' => 1, // 'slug' => 1, // 'type' => 1, // 'rating' => ['$avg' => '$rating.rate'], // 'food' => 1, // 'category' => 1 // // 'food.rating' => '$food.rating.rate' // ] // ] // ]; // $place = $db->places->aggregate($pipeline)->toArray(); return response()->json(['food' => true, 'place' => $place]); } /** * Get Place details * * @param string $slug Place slug **/ public function newPlace(string $slug) { $db = $this->getMongoDB(); // return response()->json(['hey' => $db]); $place = $db->placing->aggregate([['$match' => ['slug' => $slug]], ['$project' => [ '_id' => 0, 'name' => 1, 'address' => 1, 'phones' => 1, 'coords' => '$location.coordinates', 'opening' => 1, 'closing' => 1, 'delivery' => 1, 'image' => 1, 'slug' => 1, 'type' => 1, 'avg_rate' => 1, 'category' => 1 ]]] )->toArray()[0]; if($place) { $place['food'] = $db->foodings->aggregate([['$match' => ['place_slug' => $slug]], [ '$project' => [ '_id' => ['$toString' => '$_id'], 'name' => 1, 'description' => 1, 'category' => 1, 'price' => 1, 'avg_rate' => 1 ]] ])->toArray(); }else { abort(404, 'Place not found'); } return response()->json(['food' => true, 'place' => $place]); } /** * Find Places with matching criteria * **/ public function find(Request $request) { $params = $request->query(); $longitude = $latitude = $rad = $page = $category = $food = $address = $parking = $seating = $delivery = ""; extract($params); $placesWithFood = Place::whereNotNull('food'); if($longitude){ $places = $placesWithFood->where('location', 'near', [ '$geometry' => [ 'type' => 'Point', 'coordinates' => [ floatval($longitude), floatval($latitude) ] ], '$minDistance' => 1, '$maxDistance' => $rad ?: 30000 ]); $places = $food ? $places->where('food.name', 'regex', "/.*$food*/i")->simplePaginate(15) : $places->simplePaginate(15); }elseif($food) { $places = $placesWithFood->where('food.name', 'regex', "/.*$food*/i")->simplePaginate(15); }else { $places = $placesWithFood->simplePaginate(15); } return response()->json($places->toArray()); } public function findPlace(Request $request) { $perPage = 15; $params = $query = $request->query(); $user = $request->user(); // Extract search params $longitude = $latitude = $rad = $page = $category = $food = $address = $parking = $seating = $delivery = $distance = $t = ""; extract($params); $id = Session::get('search_id'); $page = $page ?: 1; $next = $other = false; $search_log = ['id' => $id, 'address' => $address, 'search_longitude' => $longitude, 'search_latitude' => $latitude, 'food' => $food, 'page' => $page, 'ts' => time(), 'user' => $user ? $user->email : '', 'page' => $page]; $db = $this->getMongoDB(); // Start pipeline build $pipeline = []; $projection = ['$project' => [ '_id' => 0, 'name' => 1, 'phones' => 1, 'address' => 1, 'coords' => '$location.coordinates', 'slug' => 1, 'image' => ['$arrayElemAt' => ['$image', 0]], 'food' => $food ? 1 : [], 'delivery' => 1, 'distance' => 1, 'avg_rate' => 1 ]]; if($user) { $projection['$project']['liked'] = ['$in' => [(string) $user->_id, '$likes']]; }else { $projection['$project']['liked'] = ['$in' => [1, '$likes']]; } if ($food) { $foodPipeline = [ '$text' => ['$search' => $food] ]; $lookupPipeline = ['$lookup' => [ 'from' => 'fooding', 'let' => ['id' => '$slug'], 'pipeline' => [ ['$match' => array_merge(['$expr' => ['$eq' => ['$place_slug', '$$id']]], $foodPipeline)], ['$limit' => 3], ['$sort' => ['score' => ['$meta' => 'textScore']]], ['$project' => [ '_id' => 0, 'name' => 1, 'avg_rate' => 1, 'score' => ['$meta' => 'textScore'] ]] ], 'as' => 'food' ]]; } if ($longitude && strtolower(trim($address)) != 'lagos') { // var_dump(['data' => ['hello' => 'world']]); $pipeline[] = $this->findByLocation([floatval($longitude), floatval($latitude)], $distance); }else { // if location query absent or if location is just lagos // find 30 random places in lagos. $search = 'Popular'; if (intval($page) !== 1) { return response()->json(['data' => [], 'next' => false, 'message' => 'enter location']); } if (!$food) { // if food query is empty as well $places = $this->getPopularPlacesWithFood($projection); }else { $pipeline[] = $lookupPipeline; $pipeline[] = ['$sample' => ['size' => 30]]; // $pipeline[] = ['$match' => ['enabled' => true]]; $pipeline[] = $projection; $places = $db->places->aggregate($pipeline)->toArray(); // $next = count($places) >= $perPage; $search = $food; } $this->logPlace($search, $places, $id); return response()->json(['data' => $places, 'next' => $next, 'query' => $search, 'location' => 'none']); } // Log query // $query['user'] = $request->user(); // $query['created'] = (new \DateTime('now'))->format('d-m-Y H:i:s'); // $db->logs->insertOne($query); // list($st, $en) = explode(" ", $food); // $lookupPipeline = $food ? ['$or' => [['$text' => ['$search' => "$food"]], ['description' => ['$regex' => "$food", '$options' => 'i']]]] : []; $message = ''; if ($food) { $pipeline[] = $lookupPipeline; $pipeline[] = ['$match' => ['food' => ['$ne' => []]]]; } if($delivery) { $pipeline[] = ['$match' => ['delivery' => ['$exists' => true, '$ne' => []]]]; } if($page){ $skip = (intval($page)-1)*$perPage; $pipeline[] = [ '$skip' => $skip ]; $pipeline[] = [ '$limit' => $perPage ]; } $pipeline[] = [ '$sort' => [ 'food.score' => -1, ] ]; $pipeline[] = $projection; $others = false; $search_result = $db->places->aggregate($pipeline)->toArray(); // var_dump(count($search_result));die; if(count($search_result) >= $perPage) { // if result is more than one page long $next = true; }else { $next = false; $slugs = array_column($search_result, 'slug'); $others = $db->places->aggregate([ $this->findByLocation([floatval($longitude), floatval($latitude)], $distance), [ '$match' => ['slug' => ['$nin' => $slugs ]] ], $projection, [ '$limit' => $perPage ] ])->toArray(); $db->search->deleteOne(['token' => $t]); } $this->logPlace($search_log, $search_result, $id); return response()->json(['data' => $search_result, 'next' => $next, 'query' => $food, 'other' => $other, 'others' => $others]); } public function getPopularPlacesWithFood($projection, $count = 30) { $db = $this->getMongoDB(); return $db->places->aggregate([ ['$match' => ['popular' => true, 'image' => ['$exists' => true], 'food' => ['$ne' => []]]], ['$sample' => ['size' => $count]], $projection ])->toArray(); } /** * @param array $place * @param mixed $category */ private function addCategory($place, $category) { $db = $this->getMongoDB(); $syn = is_array($category) ? ['$each' => $category] : $category; return $db->places->updateOne([ ['slug' => $place['slug']], ['$push' => ['category' => $syn]] ]); } /** * */ public function logPlace($search, $places, $id) { $places_file = storage_path(sprintf('app/places_result/%s.json', $id)); $search_file = storage_path(sprintf('app/search_result/%s.json', $id)); // var_dump('hello');die; $fh_search = fopen($search_file, "w"); $fh_places = fopen($places_file, "a"); if($fh_search && $fh_places) { fwrite($fh_search, json_encode($search)); foreach($places as $place){ $formatted = [ 'place_name' => $place['name'], 'place_slug' => $place['slug'], 'address' => $place['address'], 'place_longitude' => $place['coords'][0], 'place_latitude' => $place['coords'][1], 'ts' => time(), 'id' => $id ]; fwrite($fh_places, json_encode($formatted) . PHP_EOL); } } fclose($fh_search); fclose($fh_places); } /** * find places by location only * * @param array $coords coordinates * @return array **/ private function findByLocation(array $coords, $distance) { return ['$geoNear' => [ 'near' => [ 'type' => 'Point', 'coordinates' => $coords, ], 'maxDistance' => intval($distance) ?: 5000, 'spherical' => true, 'distanceField' => 'distance' ]]; } /** * Search for places by name or part of name * * @param string $search * @return Response **/ public function search(string $search) { $db = $this->getMongoDB(); $stripped_query = preg_replace("/[')(]/", "", $search); try { $places = $db->places->find(['nickname' => ['$regex' => "$stripped_query", '$options' => 'i'], 'enabled' => true], ['projection' => ['_id' => 0, 'name' => 1, 'slug' => 1, 'nickname' => 1]]); return response()->json($places->toArray()); }catch (\Exception $e) { return response()->json([]); } } public function address(string $address) { $db = $this->getMongoDB(); $pipeline = []; $pipeline[] = [ '$match' => ['address' => ['$regex' => "$address", '$options' => 'i'], 'phones' => ['$ne' => []]] ]; $pipeline[] = ['$lookup' => [ 'from' => 'fooding', 'localField' => 'slug', 'foreignField' => 'place_slug', 'as' => 'food' ]]; // $pipeline[] = ['$match' => ['$or' => [['food' => null], ['food' => ['$size' => 0]]]]]; $pipeline[] = ['$match' => ['food' => ['$ne' => []]]]; $pipeline[] = ['$project' => ['_id' => 0, 'name' => 1, 'address' => 1, 'phones' => 1, 'opening' => 1, 'closing' => 1]]; // $places = $db->places->find(['address' => ['$regex' => "$address", '$options' => 'i']]); $places = $db->places->aggregate($pipeline)->toArray(); return response()->json($places); } /** * Search for places by name or part of name with no food * * @param string $search * @return Response **/ public function searchNoFood(string $search) { $db = $this->getMongoDB(); try { $pipeline = []; $pipeline[] = ['$match' => ['name' => ['$regex' => "$search", '$options' => 'i']]]; $pipeline[] = ['$lookup' => [ 'from' => 'fooding', 'let' => ['id' => '$slug'], 'pipeline' => [], 'as' => 'food' ]]; // $pipeline[] = ['$match' => ['food' => ['$ne' => [], '$exists' => true]]]; // $pipeline[] = ['$project' => ['_id' => 0, 'name' => 1, 'slug' => 1]]; $places = $db->places->aggregate($pipeline); return response()->json($places->toArray()); }catch (\Exception $e) { return response()->json(['error' => $e->getMessage()]); } } /** * Show a place or list of places from a search. * * @return \Illuminate\Http\Response */ public function searchPlaces() { if (isset($_GET['name']) && $search = $_GET['name']) { $query = urldecode(implode(" ", explode("+", $search))); $places = Place::where('name', 'like', "%$query%")->simplePaginate(15); // if ($places->get()->count() === 1) return redirect()->route('places.show', ['slug' => $places->get()[0]['slug']]); if ($places->count()) return response()->json($places->toArray()); abort(404, "Place was not found"); }else { $places = Place::simplePaginate(15); } return response()->json($places->toArray()); } /** * Find places by category * * @param string $category * @return Response **/ public function findByCategory(string $category) { $places = Place::where('type', $category)->simplePaginate(15); return response()->json($places->toArray()); } /** * Search for places by name or part of name * * @param string $search * @return Response **/ public function searchFranchise(string $search = "") { if($search){ $place = Place::where('name', $search)->first(); if($place){ $food = Foods::where('place_slug', $place->slug)->get(); if($place && count($food)){ $name = substr(explode(" (", urldecode($search))[0], 0, 5); $places = DB::table('places') ->select(['name', 'slug']) ->where('name', 'like', "$name%") ->where('name', '!=', $search) ->get(); return response()->json(['place' => urldecode($search), 'franchises' => $places->toArray()]); } return response()->json(['franchises' => [], 'error' => 'Place found but no food']); } return response()->json(['franchises' => [], 'error' => 'Place not found']); } return response()->json(['franchises' => [], 'error' => 'Empty query']); } public function findFranchisesWithFood(string $search = "") { if(!$search) return response()->json(['franchises' => [], 'error' => 'Empty query']); $db = $this->getMongoDB(); $name = substr(explode(" (", urldecode($search))[0], 0, 8); $franchises = $db->places->aggregate( [ ['$match' => [ '$and' => [ ['name' => ['$ne' => $search]], ['name' => ['$regex' => "^$name", '$options' => 'i']] ] ]], ['$lookup' => [ 'from' => 'fooding', 'let' => ['id' => '$slug'], 'pipeline' => [ ['$match' => [ '$expr' => [ '$eq' => ['$place_slug', '$$id'] ] ]], ['$project' => [ '_id' => ['$toString' => '$_id'], 'name' => 1, 'place_slug' => 1, 'place_name' => 1, 'description' => 1, 'category' => 1, 'price' => 1 ]] ], 'as' => 'food' ]], ['$match' => ['food' => ['$exists' => true, '$ne' => []]]], ['$project' => ['_id' => 0, 'name' => 1, 'slug' => 1, 'type' => 1, 'category' => 1, 'food' => 1, 'franchise' => 1]] ] )->toArray(); if(count($franchises)) { for ($i=0; $i < count($franchises[0]['food']); $i++) { $franchises[0]['food'][$i]['_id'] = (string) $franchises[0]['food'][$i]['_id']; } } return response()->json($franchises); } /** * Sync franchise food * * Populate franchise locations with the same menu * * @param string $name **/ public function postFranchise(string $name) { $place = Place::where('name', $name)->first(); $db = $this->getMongoDB(); $foods = $db->fooding->find(['place_slug' => $place->slug])->toArray(); $places = $db->places->find(['slug' => ['$in' => $_POST['franchise']]])->toArray(); // $result = $db->places->updateMany(['slug' => ['$in' => $_POST['franchise']]], ['$set' => ['food' => $place->food->toArray(), 'tags' => $place->tags, 'type' => $place->type]]); // $result = $db->fooding->insertMany([]) // var_dump([$places, $foods]);die; $db->fooding->deleteMany(['place_slug' => ['$in' => $_POST['franchise']]]); $db->places->updateMany(['slug' => ['$in' => array_merge($_POST['franchise'], [$place->slug])]], ['$set' => ['franchise' => $place->slug, 'category' => $place->category, 'type' => $place->type]]); if (count($foods) && count($places)) { foreach ($foods as $food) { foreach ($places as $placeTo) { $result = $db->fooding->insertOne([ 'name' => $food['name'], 'price' => $food['price'], 'description' => $food['description'] ?? '', 'category' => $food['category'] ?? '', 'place_name' => $placeTo['name'], 'place_slug' => $placeTo['slug'] ]); } } } return response()->json(['message' => 'done']); } /** * Slugify place name * * A method that converts the name of a place to a slug * * @param string $name * @return String **/ // private function slugify(string $name) // { // $result = DB::collection('places')->where('name', '=', $name)->get()->toArray(); // if ($length = count($result) !== 0) { // $slugged = implode("-", explode(" ", strtolower($name))) . '-' . $length; // return $slugged; // } // return implode("-", explode(" ", strtolower($name))); // } /** * Get food that a place serves * * @param string $name Place name **/ public function food(string $name) { $db = $this->getMongoDB(); $place = $db->places->findOne(['name' => $name]); $food = $db->fooding->find(['place_slug' => $place['slug']])->toArray(); if(count($food)) { // $place = $place[0]; for ($i=0; $i < count($food); $i++) { $food[$i]['_id'] = (string) $food[$i]['_id']; } } return response()->json(['food' => $food, 'place' => $place], 200, ['Content-Type' => 'application/json']); } /** * Get place details using name * * @param string $name Place name **/ public function details(string $name) { $db = $this->getMongoDB(); $place = $db->places->aggregate([['$match' => ['name' => $name]], ['$project' => ['_id' => 0, 'name' => 1, 'address' => 1, 'phone' => 1]]]); return response()->json($place->toArray()); } public function saveNewPlace(Request $request) { $place = json_decode($request->getContent(), true); $db = $this->getMongoDB(); $date = (new \DateTime('now'))->format('d-m-Y H:i:s'); $place['added'] = $date; $res = $db->suggest->insertOne($place); return response()->json(['status' => 'success', 'message' => 'Thank you for your suggestion. We will review and update our database.']); } public function unsetVariables($user, $POST) { $extras = [ 'name' => trim($POST['name']), 'image' => $POST['uploadimage'] ?? [], 'phones' => array_filter($POST['phone']), 'created' => (new \DateTime('now'))->format('d-m-Y H:i:s'), 'user' => (string) $user->email, 'location' => array( 'type' => 'Point', 'coordinates' => [floatval($POST['longitude']) ?? 0, floatval($POST['latitude']) ?? 0] ) ]; $slug = $POST['edit'] ?? null; $food = $POST['food'] ?? null; unset($POST['phone'], $POST['longitude'], $POST['latitude'], $POST['food'], $POST['edit'], $POST['_token'], $POST['uploadimage']); return array($extras, $slug, $food, $POST); } /** * Save a new place or edit an existing one. * * @return \Illuminate\Http\Response */ public function store(Request $request) { $db = $this->getMongoDB(); $user = $request->user(); $data = json_decode($request->getContent(), true); list($extras, $slug, $food, $post) = $this->unsetVariables($user, $data); $escaped_name = preg_replace('/\/|\'/', "-", $extras['name']); $slug = $slug ?: $this->slugify($escaped_name); $images = $toProcess = []; $files = $this->handleArrayInput($_FILES['image']); $oldImages = $data['uploadimage'] ?? []; $c = count($oldImages); foreach ($files as $file) { if(isset($file['tmp_name']) && $file['tmp_name']){ $toProcess[$c] = $file; $base_image = "/places/images/" . $slug . "-$c.jpg"; $images[] = env('S3_BASE_URL') . $base_image; $c++; } } ProcessImage::dispatch($slug, $toProcess); $extras['image'] = count($images) < 2 ? array_merge($images, $oldImages) : $images; $place = array_merge($post, $extras); $updated = $db->places->findOneAndUpdate( ['slug' => $slug], ['$set' => $place], [ 'upsert' => true, 'returnDocument' => \MongoDB\Operation\FindOneAndUpdate::RETURN_DOCUMENT_AFTER ] ); // if update, check if place is part of franchise and get list of franchise places // else put stored place in an array of one and return // $franchise = $updated ? $this->updateFranchise($updated) : [$db->places->findOne(['_id' => $newPlace->getInsertedId()])]; if($food) $this->saveFood($updated, $food); return redirect()->route('places.show', ['place' => $updated['slug']]); } /** * Traverse an array and * @param array $arrayInput * @return array */ private function handleArrayInput(array $arrayInput) { try { $keys = array_keys($arrayInput); $f = array(); for ($i=0; $i < count($arrayInput[$keys[0]]); $i++) { $n = array(); foreach ($keys as $key) { $n[$key] = $arrayInput[$key][$i]; } $f[] = $n; } return $f; } catch (\Exception $e) { } } /** * Save food items belonging to a place * * @param Place $place Place instance * @param array $foodpost food items from form **/ public function saveFood($place, $foodpost) { $f = $this->handleArrayInput($foodpost); $db = $this->getMongoDB(); $user = Auth::user(); foreach($f as $foodDetails) { // Check if food name already exists in database if (isset($foodDetails['food']) && $foodDetails['food']) { $food = []; $id = $foodDetails['id'] ?? ''; $food['name'] = $foodDetails['food']; $food['price'] = $foodDetails['price'] ?? 0; $food['category'] = $foodDetails['foodCategory'] ?? ''; $food['description'] = $foodDetails['description'] ?? ''; $food['place_name'] = $place['name']; $food['place_slug'] = $place['slug']; $at_keys = $id ? ['updated', 'modified_by'] : ['created', 'created_by']; $food[$at_keys[0]] = (new \DateTime('now'))->format('d-m-Y H:i:s'); $food[$at_keys[1]] = (string) $user->email; if($id){ // If not edit $d = $db->fooding->updateOne( [ '_id' => new \MongoDB\BSON\ObjectId($id) ], [ '$set' => $food ], [ '$upsert' => true ] ); }else{ $db->fooding->insertOne($food); } } } return true; } public function likePlace(Request $request, $slug) { $db = $this->getMongoDB(); // $place = $db->places->findOne(['slug' => $slug]); $user = $request->user(); $liked = $db->places->updateOne( [ "slug" => $slug ], [ '$addToSet' => [ "likes" => (string) $user->_id ] ], [ 'upsert' => true ] ); $stat = $liked->isAcknowledged() ? 'success' : 'failed'; return response()->json(['status' => $stat]); } public function likes(Request $request, $slug) { $db = $this->getMongoDB(); $place = $db->places->findOne(['slug' => $slug]); if($place && isset($place['likes'])){ return response()->json(['status' => 'success', 'likes' => $place['likes']]); } return response()->json(['status' => 'error']); } public function likeReview(Request $request, $id) { $db = $this->getMongoDB(); $data = json_decode($request->getContent(), true); $type = $data['type']; // $index = $data['index']; $user = Auth::user(); $db->$type->updateOne([ "_id" => new \MongoDB\BSON\ObjectId($data['id']), "rating.id" => $id ], [ '$addToSet' => [ "rating.$.likes" => '5d9631a117d3e759f40d6674' ] ]); } public function deleteFood($id) { $db = $this->getMongoDB(); $result = $db->fooding->deleteOne(['_id' => new \MongoDB\BSON\ObjectId($id)]); return response()->json($result->getDeletedCount()); } }
Close