示例#1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['function' => 'required', 'user_id' => 'required', 'ratings' => 'required']);
     if ($validator->fails()) {
         if ($validator->errors()->has('function')) {
             return response()->json($validator->errors()->first('function'), 400);
         }
         if ($validator->errors()->has('user_id')) {
             return response()->json($validator->errors()->first('user_id'), 400);
         }
         if ($validator->errors()->has('ratings')) {
             return response()->json($validator->errors()->first('ratings'), 400);
         }
     }
     $review = Review::whereuser_id($request->user_id)->where('function', $request->function)->first();
     if ($review) {
         $review->ratings = $request->ratings;
         if ($request->review) {
             $review->feedback = $request->review;
         }
         $review->update();
     } else {
         $review = new Review();
         $review->user_id = $request->user_id;
         $review->ratings = $request->ratings;
         $review->function = $request->function;
         if ($request->review) {
             $review->feedback = $request->review;
         }
         $review->save();
     }
     return response()->json($review);
 }
 /**
  * Store a newly review to user
  *
  * @param ReviewRequest $request
  * @return Response
  */
 public function postReview($username, ReviewRequest $request)
 {
     $input = array_add($request->all(), 'author_id', Auth()->user()->id);
     $user = $this->userRepository->findByUsername($username);
     $review = new Review();
     $review->storeReviewForUser($user->id, $input['author_id'], $input['comment'], $input['rating']);
     return Redirect()->route('profile_reviews', $user->username);
 }
示例#3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postReview(Request $request, $id)
 {
     $model = new Review();
     $model->staff_id = $id;
     $model->reviewer_id = Auth::user()->id;
     $model->point = $request->point;
     $model->comment = $request->content;
     $model->save();
     return redirect()->route('admin.index')->with('success', 'Added completely!');
 }
示例#4
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $review = new Review();
     $id = Input::get('id');
     $review->product_id = $id;
     $review->name = Input::get('name');
     $review->email = Input::get('email');
     $review->message = Input::get('message');
     $review->save();
     return redirect()->route('product-details', $id);
 }
 public function submitReview($id)
 {
     $input = array('comment' => Input::get('comment'), 'rating' => Input::get('rating'));
     // instantiate Rating model
     $review = new Review();
     // Validate that the user's input corresponds to the rules specified in the review model
     $validator = Validator::make($input, $review->getCreateRules());
     // If input passes validation - store the review in DB, otherwise return to product page with error message
     if ($validator->passes()) {
         $review->storeReviewForProduct($id, $input['comment'], $input['rating']);
         return \Redirect::to('products/' . $id . '#reviews-anchor')->with('review_posted', true);
     }
     return \Redirect::to('products/' . $id . '#reviews-anchor')->withErrors($validator)->withInput();
 }
 public function __construct(User $user, Request $request, Review $review)
 {
     //ミドルウェアでゲストユーザをフィルタ
     $this->middleware('auth');
     if (!Auth::check()) {
         //ログインチェック
         return redirect()->to("/auth/login");
     }
     //他人のレビューを改竄しようとしたユーザーをフィルタ
     $this->middleware("validReviewer", ["only" => ["getEdit", "postEditConfirm", "postEditComplete", "postDeleteConfirm", "postDeleteComplete"]]);
     $user_id = $request->user()->user_id;
     $this->user = $user->find($user_id);
     $this->review = $review->where('user_id', '=', $user_id)->get();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $author = User::where('name', '=', 'Jamie Shepherd')->first();
     $node = Node::where('category', '=', 'films')->where('title', '=', 'Inception')->first();
     $review = new Review();
     $review->author = array('reference' => $author->_id, 'name' => $author->name, 'gravatar' => md5(strtolower(trim($author->email))));
     $review->node = array('reference' => $node->_id, 'title' => $node->title);
     $review->score = 7.9;
     $review->review = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.';
     $review->thumbs = 0;
     $review->save();
     $node->avg = number_format(round(Review::where('node.reference', $node->_id)->avg('score'), 1), 1);
     $node->increment('reviewCount');
     $node->save();
 }
示例#8
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store()
 {
     $review = new Review();
     $input = Input::all();
     $validator = $this->checkValidation();
     if ($validator->fails()) {
         $messages = $validator->messages();
         foreach ($messages->all() as $message) {
             $msg[] = $message;
         }
         return $this->errorMessage($msg);
     }
     $saveReview = $review->insert($input);
     $msg = "Review saved successfully.";
     return $this->successMessageWithVar($msg, $saveReview);
 }
示例#9
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(ReviewRequest $request)
 {
     $data = $request->all();
     $data['user_id'] = Auth::user()->id;
     Review::create($data);
     return redirect('/product/' . $request->get('product_id'));
 }
示例#10
0
 public function reviews($id)
 {
     $reviews = Review::with(['user' => function ($query) {
         $query->select('id', 'name');
     }])->select('id', 'user_id', 'title', 'content', 'visible', 'created_at', 'banned')->where('episode_id', $id)->orderBy('id', 'desc')->simplePaginate(10);
     return $reviews;
 }
示例#11
0
 public static function average($param)
 {
     // average review of last month
     $average = Review::where(['active' => 1, 'staff_id' => $param])->whereBetween('created_at', [Carbon::now()->subMonths(1)->startOfMonth(), Carbon::now()->subMonths(1)->endOfMonth()])->get();
     $avg = collect($average);
     return $avg->avg('point');
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $title = "View Review";
     $review = Review::where('staff_id', $id)->orderBy('created_at')->first();
     // var_dump($review->toArray());exit();
     return view('html.review.view', compact('review', 'title'));
 }
示例#13
0
 /**
  * Возвращает объект отзыва или пустой результат.
  *
  * Запоминает в сессии 10 последних отзывов.
  * Отзыв выбирается из базы рандомно исключая отзывы из сессии.
  *
  * @return Review|null
  */
 protected function __getReview()
 {
     $review_ids = Request::session()->get('review_ids');
     $where = Review::withTrashed()->with('profile');
     if (!is_null($review_ids)) {
         $where->whereNotIn('id', $review_ids);
     }
     $where->orderByRaw('RAND()');
     $where->limit(1);
     $reviews = $where->get();
     $review = null;
     if ($reviews) {
         $review = $reviews[0];
     }
     if (is_null($review_ids)) {
         $review_ids = [];
     }
     if (sizeof($review_ids) >= 30) {
         $review_ids = array_slice($review_ids, 1);
     }
     if (sizeof($review_ids) < 30) {
         array_push($review_ids, $review->id);
     }
     Request::session()->set('review_ids', $review_ids);
     return $review;
 }
 public static function findUniqueUrl($title)
 {
     $count = Review::where('title', $title)->count();
     if ($count > 0) {
         return self::titleToUrl($title . '-' . $count);
     }
     return self::titleToUrl($title);
 }
示例#15
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     for ($i = 1; $i <= 50; $i++) {
         $review = ['email' => $faker->email, 'name' => $faker->name, 'text' => $faker->text(rand(300, 1000)), 'ip' => $faker->ipv4, 'active' => 1];
         Review::create($review);
     }
     //
 }
 /**
  * @param TravelCompany $travelCompany
  * @param $slug
  *
  * @internal param $travel_companies
  *
  * @return \Illuminate\View\View
  */
 public function single(TravelCompany $travelCompany, $slug)
 {
     $company = $travelCompany->where('slug', $slug)->first();
     $stations = $company->stations;
     $reviews = Review::where('travel_company_id', $company->id)->get();
     $images = $company->travel_company_picture;
     $bus_features = $company->bus_features;
     // dd($images);
     return view('companies.terminal', ['company' => $company, 'stations' => $stations, 'reviews' => $reviews, 'images' => $images, 'bus_features' => $bus_features]);
 }
示例#17
0
 public function postDelete(ReviewRequest $request, Review $review)
 {
     try {
         $input = $request->all();
         $id = $input['id'];
         $deleteReview = $review->where('id', $id)->first();
         $deleteReview->delete();
         $message = 'Delete Success';
         $msg_type = 'success';
     } catch (Exception $e) {
         $message = 'Delete Error';
         $msg_type = 'danger';
         // return response()->json((['error'=>$e->getMessage()]), 422);
     }
     return $message;
     // return redirect('/product')->with([
     //                                     'message' => $message,
     //                                     'type' => $msg_type,
     //                                 ]);
 }
示例#18
0
 /**
  * @param     $id
  * @param int $skip
  * @param int $take
  *
  * @return mixed
  */
 public static function getReviewsById($id, $uid = false, $skip = 0, $take = 10)
 {
     $data = ['product_id' => $id];
     if ($uid) {
         $data['uid'] = $uid;
     }
     $result = Review::where($data)->skip($skip)->take($take)->get();
     if ($uid) {
         $result = !empty($result[0]) ? $result[0] : false;
     }
     return $result;
 }
 /**
  * Display the specified resource.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     if ($movie = Movie::with('genre')->find($id)->toArray()) {
         $genres = Genre::get()->toArray();
         $reviews = Review::with('movie')->where('movie_id', $id)->get()->toArray();
         $avgKernals = $this->calculateKernals($reviews);
         return view('movies.show')->with('movie', $movie)->with('genres', $genres)->with('reviews', $reviews)->with('kernals', $avgKernals);
     }
     // User doesn't exist for this account
     $this->setMessage('Movie not found!', 'error');
     return redirect('/movies');
 }
 /**
  * Display the specified resource.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     if ($customer = $this->getRentalHistory($id)) {
         $reviews = Review::where('customer_id', $id)->with('movie')->get()->toArray();
         $wishlist = Wishlist::where('customer_id', $id)->with('movies')->get()->toArray();
         // dd($wishlist);
         return view('customers.show')->with('customer', $customer)->with('reviews', $reviews)->with('wishlist', $wishlist);
     }
     // User doesn't exist for this account
     $this->setMessage('Customer not found!', 'error');
     return redirect('/customers');
 }
示例#21
0
 public function getViewproduct($id)
 {
     $product = Product::find($id);
     if ($product == null) {
         return redirect('dashboard')->with(['message' => 'Invalid Request.', 'type' => 'danger']);
     }
     $favourite = Preference::where('user_id', Auth::user()->id)->where('product_id', $id)->first();
     $review = Review::where('user_id', Auth::user()->id)->where('product_id', $id)->first();
     $allReviews = $this->orderReview($id);
     $allComparisons = $this->userSkinComparison($id);
     return view('product')->with('product', $product)->with(['favourite' => $favourite, 'review' => $review, 'allReviews' => $allReviews, 'allComparisons' => $allComparisons]);
 }
示例#22
0
 public function deleteReview(Request $request)
 {
     $this->validate($request, ['review_id' => 'required|integer', 'created_at' => 'required|date', 'reason' => 'required|max:255']);
     $review = Review::find($request->input('review_id'));
     if ($review->created_at == $request->input('created_at')) {
         $review->banned = $request->input('reason');
         if ($review->save()) {
             return redirect('/');
         } else {
             return redirect()->back()->withInput()->withErrors('屏蔽失败');
         }
     }
     return redirect()->back()->withInput()->withErrors('校验失败,请仔细核对评论ID与评论时间');
 }
 public function update(Request $request, $id)
 {
     $param = $request->all();
     $review = Review::find($id);
     $review->update($param);
     $requirement = $review->requirement;
     if ($review->status == 'pass') {
         $requirement->status = 'passed';
     } elseif ($review->status == 'unpass') {
         $requirement->status = 'opening';
     }
     $requirement->save();
     return $review;
 }
示例#24
0
 /**
  * @return \Illuminate\Http\JsonResponse
  */
 public function review()
 {
     header("Access-Control-Allow-Origin: *");
     $response = new YYResponse(FALSE, 'Something went wrong.');
     $validator = Validator::make(Request::all(), ['product_id' => 'required|integer', 'uid' => 'required|integer', 'rating' => 'required|integer']);
     if ($validator->fails()) {
         $response->errors = $validator->errors();
         return response()->json($response);
     }
     $review = Review::where(['uid' => Request::get('uid'), 'product_id' => Request::get('product_id')])->first();
     if (!$review) {
         $review = new Review();
     }
     $review->comment = Request::get('comment', null);
     $review->uid = Request::get('uid');
     $review->product_id = Request::get('product_id');
     $review->rating = Request::get('rating');
     if ($review->save()) {
         $response->state = true;
         $response->message = 'Review created.';
     }
     return response()->json(['state' => TRUE]);
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function create($category, $slug)
 {
     $node = Node::where('category', $category)->where('slug', $slug)->first();
     $score = 0.0;
     if (Input::get('score') == 10) {
         $score = 10;
     } else {
         $score = Input::get('score');
     }
     // If it's the first review, reward the user
     if (Review::where('node.reference', $node->_id)->count() == 0) {
         Auth::user()->points += 1000;
         Auth::user()->save();
     }
     // Create the review
     $review = new Review();
     $review->node = array('reference' => $node->_id, 'title' => $node->title);
     $review->author = array('reference' => Auth::user()->_id, 'name' => Auth::user()->name, 'gravatar' => md5(strtolower(trim(Auth::user()->email))));
     $review->score = (double) $score;
     $review->review = Input::get('review');
     $review->thumbs = 0;
     $review->spoilers = Input::has('spoilers');
     $review->save();
     if ($review->score < 4) {
         $node->increment('overall_negative');
     } else {
         if ($review->score < 7) {
             $node->increment('overall_mixed');
         } else {
             $node->increment('overall_positive');
         }
     }
     $node->avg = number_format(round(Review::where('node.reference', $node->_id)->avg('score'), 1), 1);
     $node->increment('reviewCount');
     $node->save();
     return back();
 }
示例#26
0
 public function destroy(Request $request, $id)
 {
     $review = Review::find($id);
     if ($review->user_id == $request->user()->id) {
         if ($review->delete()) {
             DB::table('users')->where('id', $review->user_id)->decrement('reviews');
             DB::table('dramas')->where('id', $review->drama_id)->decrement('reviews');
             if ($review->episode_id) {
                 DB::table('episodes')->where('id', $review->episode_id)->decrement('reviews');
             }
             return ['result' => 'success'];
         }
     }
     return response('非评论用户', 422);
 }
示例#27
0
 public function lists()
 {
     //最新剧单
     $newLists = Dramalist::select('id', 'title')->orderBy('id', 'desc')->take(10)->get();
     //查询60天收藏数前10的剧单
     $hotLists = Listfav::with(['dramalist' => function ($query) {
         $query->select('id', 'title');
     }])->select(DB::raw('count(*) as favorite_count, list_id'))->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-60 day")))->groupBy('list_id')->orderBy('favorite_count', 'desc')->take(10)->get();
     //查询30天评论数前10的剧集id
     $hotDramas = Review::with(['drama' => function ($query) {
         $query->select('id', 'title');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as review_count, drama_id'))->groupBy('drama_id')->orderBy('review_count', 'desc')->take(10)->get();
     //查询30天收藏前10的剧集id
     $hotFavorites = Favorite::with(['drama' => function ($query) {
         $query->select('id', 'title');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as favorite_count, drama_id'))->groupBy('drama_id')->orderBy('favorite_count', 'desc')->take(10)->get();
     return ['newLists' => $newLists, 'hotLists' => $hotLists, 'hotDramas' => $hotDramas, 'hotFavorites' => $hotFavorites];
 }
示例#28
0
 public function getIndex()
 {
     $products = Product::all();
     foreach ($products as $aProduct) {
         $related_usr = array();
         $favs = Preference::where('product_id', $aProduct->id)->where('flag', '1')->get();
         foreach ($favs as $aFav) {
             array_push($related_usr, $aFav->user);
         }
         $reviews = Review::where('product_id', $aProduct->id)->where('rating', '1')->get();
         foreach ($reviews as $aReview) {
             if (!in_array($aReview->user, $related_usr)) {
                 array_push($related_usr, $aReview->user);
             }
         }
         if (count($related_usr) > 4) {
             $aProduct->gettrained($related_usr);
         }
     }
 }
示例#29
0
 public function reviews(Request $request)
 {
     if ($request->has('type')) {
         $type = $request->input('type');
     } else {
         $type = 0;
     }
     if ($type < 0) {
         $reviews = Review::join('dramas', 'reviews.drama_id', '=', 'dramas.id')->where('reviews.visible', '=', 1)->select('reviews.*', 'dramas.title as drama_title')->orderBy('id', 'desc')->simplePaginate(20);
     } else {
         $reviews = Review::join('dramas', 'reviews.drama_id', '=', 'dramas.id')->where('dramas.type', '=', $type)->where('reviews.visible', '=', 1)->select('reviews.*', 'dramas.title as drama_title')->orderBy('id', 'desc')->simplePaginate(20);
     }
     $reviews->load(['user' => function ($query) {
         $query->select('id', 'name');
     }]);
     $reviews->load(['episode' => function ($query) {
         $query->select('id', 'title');
     }]);
     return view('review.reviews', ['reviews' => $reviews]);
 }
示例#30
0
 /**
  * Post the review form.
  *
  * @return Response
  */
 public function postAddReview(Request $request)
 {
     //validation
     $v = Validator::make($request->all(), ['star' => 'required|integer|in:1,2,3,4,5', 'review' => 'required|string']);
     //Checking validation outcome
     if ($v->fails()) {
         /**
          * Validation failed
          * Redirecting back to the page with errors and inputs
          */
         return back()->withErrors($v)->withInput();
     } else {
         /**
          * Validation passed
          * Checking if the learner has already submitted a review for the instructor
          */
         $no_of_review = Review::where('learner_id', $request->user()->learner->learner_id)->where('Instructor_id', $request->instructor_id)->count();
         if ($no_of_review == 0) {
             //If no review has submitted for the selected instructor by the current user
             //Create the review
             $review = Review::create(['learner_id' => $request->user()->learner->learner_id, 'instructor_id' => $request->instructor_id, 'rating' => $request->star, 'review' => $request->review]);
             if ($review) {
                 //If review is created successfully
                 //Send an e-mail to the instructor
                 /*Write an e-mail function here*/
                 //Redirect the user
                 return redirect()->route('home')->with('message', 'Review added')->with('alert-class', 'alert-success');
             } else {
                 //If creating review was unsuccessfull
                 return redirect()->route('home')->with('message', 'Review could not be added')->with('alert-class', 'alert-danger');
             }
             //End of if statement
         } else {
             //If review has been submitted previously for the selected instructor by the current user
             return redirect()->route('home')->with('message', 'You have already submitted a review for this instructor!')->with('alert-class', 'alert-danger');
         }
         //End of if statement
     }
     //End of if statement
 }