Ejemplo n.º 1
0
 /**
  * Create a new authentication controller instance.
  *
  * @return void
  */
 public function __construct(Request $request)
 {
     $this->middleware('guest', ['except' => 'getLogout']);
     $favorites = ProfileController::getFavorites($request);
     view()->share('favorites', $favorites);
     User::detectUserLocation();
 }
Ejemplo n.º 2
0
 public function __construct(Request $request)
 {
     $favorites = ProfileController::getFavorites($request);
     view()->share('favorites', $favorites);
 }
Ejemplo n.º 3
0
 public function filterPosts(Request $request)
 {
     $query = $request->city_id ? 'city_id = ' . (int) $request->city_id . ' AND ' : NULL;
     $query .= $request->image == 'on' ? 'image IS NOT NULL AND ' : NULL;
     $query .= $request->from ? 'price >= ' . (int) $request->from . ' AND ' : 'price >= 0 AND ';
     $query .= $request->to ? 'price <= ' . (int) $request->to : 'price <= 9999999999';
     if ($request->text) {
         $text = trim(strip_tags($request->text));
         $query .= " AND (title LIKE '%{$text}%' or description LIKE '%{$text}%')";
     }
     $section = Section::all();
     $profiles = Profile::take(5)->get();
     if ($request->category_id) {
         $section = Section::find($request->category_id);
         $posts = Post::where('status', 1)->where('category_id', $request->category_id)->whereRaw($query)->orderBy('id', 'DESC')->paginate(10);
         $posts->appends(['category_id' => (int) $request->category_id, 'city_id' => (int) $request->city_id, 'text' => $request->text, 'image' => $request->image == 'on' ? 'on' : NULL, 'from' => (int) $request->from, 'to' => (int) $request->to, 'tag_id' => $request->tags_id]);
     } else {
         $posts = Post::where('status', 1)->whereRaw($query)->orderBy('id', 'DESC')->paginate(10);
         $posts->appends(['city_id' => (int) $request->city_id, 'text' => $request->text, 'image' => $request->image == 'on' ? 'on' : NULL, 'from' => (int) $request->from, 'to' => (int) $request->to, 'tag_id' => $request->tags_id]);
     }
     $selected_tags = [];
     if (isset($request->tags_id)) {
         $selected_tags = $request->tags_id;
         foreach ($posts as $post_key => $post) {
             $hasTag = false;
             foreach ($selected_tags as $tag_id) {
                 if ($post->hasTag($tag_id)) {
                     $hasTag = true;
                 }
             }
             if (!$hasTag) {
                 unset($posts[$post_key]);
             }
         }
     }
     $category = Category::findOrFail($request->category_id);
     $category_tags = $category->tags()->get();
     $favorites = ProfileController::getFavorites($request);
     $favorites = $favorites ? $favorites : [];
     return view('board.posts', compact('category', 'category_tags', 'selected_tags', 'section', 'sections', 'profiles', 'posts', 'favorites'));
 }