public function deleteReview(Request $request) { $id = $request->id; $review = Reviews::find($id); if ($review->delete()) { return response()->json(['response' => 'Deleted Review', 'product_ref' => $review->product_ref]); } else { return response()->json(['response' => 'Could Not Delete Review']); } }
/** * @auther mayura * adding reviews to a particular used item * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function add_item_review() { $login_id = Input::get('login_id'); // if (Auth::loginUsingId($login_id)){ $reviews = new Reviews(); $reviews->id = Input::get('item_id'); $reviews->email = Auth::user()->email; $reviews->comment = Input::get('comment'); $count = DB::table('reviews')->orWhere(function ($query) { $query->where('email', Auth::user()->email); })->where('id', Input::get('item_id'))->count(); if ($count == 0) { $reviews->save(); } else { DB::table('reviews')->orWhere(function ($query) { $query->where('email', Auth::user()->email); })->where('id', Input::get('item_id'))->update(['comment' => Input::get('comment')]); } return redirect('item_review.' . Input::get('item_id')); // }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { //Default for number of images in the post $num_img = 0; $locationID = null; $taglist = null; if (Auth::user()->uuid) { if ($request->data) { $json = $request->data; $topicUUID = rand(0, 10) . str_random(12) . rand(0, 10); $topicSlug = str_slug($json['title'], "-") . '-' . $topicUUID; //Reviews if ($json['reviews'] != 'false') { $count = 0; foreach ($json['reviews'] as $review) { //there is a bug that says name is empty sometime if (!empty($review['name'])) { $review_data[$count] = array('topic_uuid' => $topicUUID, 'user_uuid' => Auth::user()->uuid, 'criteria' => $review['name'], 'scores' => $review['rating'], 'is_template' => TRUE, 'created_at' => date("Y-m-d H:i:s")); $count++; } } Reviews::insert($review_data); } //Location if (!empty($json['location'])) { $locationID = $json['location']['id']; //Check location exists, if not create $location_exist = DB::table('locations')->where('external_id', $locationID)->count(); if ($location_exist == 0) { $location = new Location(); $location->source = 'facebook'; //hardcode for now $location->external_id = $locationID; $location->name = $json['location']['name']; $location->category = !empty($json['location']['category']) ? $json['location']['category'] : null; $location->street = !empty($json['location']['location']['street']) ? $json['location']['location']['street'] : null; $location->city = !empty($json['location']['location']['city']) ? $json['location']['location']['city'] : null; $location->state = !empty($json['location']['location']['state']) ? $json['location']['location']['state'] : null; $location->country = !empty($json['location']['location']['country']) ? $json['location']['location']['country'] : null; $location->zip = !empty($json['location']['location']['zip']) ? $json['location']['location']['zip'] : null; $location->latitude = $json['location']['location']['latitude']; $location->longitude = $json['location']['location']['longitude']; $location->save(); } //GEt the ID } //Tag list - to store in the topic table if (!empty($json['tags'])) { $taglist = implode(",", $json['tags']); } //Images if (!empty($json['images'])) { $count = 0; //Insert images in another table foreach ($json['images'] as $image) { $img_data[$count] = array('topic_uuid' => $topicUUID, 'user_uuid' => Auth::user()->uuid, 'filename' => $image, 'created_at' => date("Y-m-d H:i:s")); $count++; } $num_img = $count; TopicImages::insert($img_data); } $topic = new Topic(); $topic->uuid = $topicUUID; $topic->type = $json['type']; $topic->uid = Auth::user()->uuid; $topic->topic = clean($json['title']); $topic->body = preg_replace('/(<[^>]+) style=".*?"/i', '$1', clean($json['body'])); $topic->text = clean($json['text']); $topic->category = $json['categories']; $topic->slug = $topicSlug; $topic->num_img = $num_img; $topic->tags = $taglist; $topic->location_id = $locationID; $topic->save(); $tag_data = array(); $count = 0; //Tags - to store in tags table if (!empty($json['tags'])) { //Insert tags in another table foreach ($json['tags'] as $tag) { Redis::zadd('post:tag' . $tag, $topic->uuid, $topic->uuid); Redis::sadd('post:' . $topic->uuid . ':tags', $tag); //Master link of tags Redis::sadd('post:tags', $tag); $tag_data[$count] = array('topic_uuid' => $topicUUID, 'title' => clean($tag), 'created_at' => date("Y-m-d H:i:s")); $count++; } Tags::insert($tag_data); } $topicEvents = Topic::find($topic->id); event(new \App\Events\TopicPostEvent($topicEvents)); $data = array("slug" => $topicSlug, "author" => Auth::user()->displayname, "type" => $json['type'], "topic_uuid" => $topicUUID); return $data; } } else { return "not login"; } }