public function validatePost($id) { if (!Auth::check()) { return Redirect::to('/login'); } $error = NULL; $title = Input::get('title'); $url = Input::get('url'); $image = NULL; $description = Input::get('description'); $newPostID = NULL; if (!empty($url) && preg_match("#https?://#", $url) == 0) { $url = 'http://' . $url; } if (empty($title)) { $error = 'Enter a title for your post'; } else { if (empty($description)) { $error = 'Enter a description for your post'; } else { $newPost = ['title' => $title, 'description' => $description, 'url' => $url, 'community_id' => $id, 'user_id' => Auth::user()->id, 'comments_count' => 0, 'points' => 1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()]; $newPostID = DB::table('posts')->insertGetId($newPost); } } if ($error) { $community = Community::find($id); return view('newpost', ['community' => $community, 'error' => $error]); } else { return Redirect::to('/post/' . $newPostID); } }
/** * Display a listing of the resource. * * @return Response */ public function index($id) { if (!Auth::check()) { return Redirect::to('/login'); } $community = Community::find($id); return view('community', ['community' => $community, 'posts' => $community->posts]); }
/** * Show the application dashboard to the user. * * @return Response */ public function dashboard() { $user = User::find(Auth::user()->id); $communitys = Community::all()->lists('name', 'id'); $feedbacksGiven = Feedback::where('giver_id', Auth::user()->id)->get(); $feedbacks = Feedback::where('receiver_id', Auth::user()->id)->get(); $activePosts = Post::where('user_id', Auth::user()->id)->where('sold', null)->get(); $offers = Offer::where('post_creator', Auth::user()->id)->whereHas('post', function ($q) { $q->where('sold', NULL); })->orderBy('created_at', 'desc')->get(); return view('pages.dashboard', ['user' => $user, 'communities' => $communitys, 'offers' => $offers, 'feedbacks' => $feedbacks, 'activePosts' => $activePosts, 'feedbacksGiven' => $feedbacksGiven]); }
/** * Execute the job. * * @return void */ public function handle() { $community = $this->property['CommunityName']; if ($community !== 'None') { $createdCommunity = \App\Community::where('community', '=', $community)->first(); if (is_null($createdCommunity)) { $this->createProperty->community()->create(['community' => $community]); } else { $this->createProperty->community()->sync([$createdCommunity->id]); } } }
public function filter(Request $request) { $allCommunities = $request->communities; $communities = Community::where('city_id', $request->city)->get(); $requestedInfo = $request; if ($request->from == '' || $request->from == 0) { $from = 1.0E+17; } else { $from = $request->from; } if (sizeof($allCommunities) > 0) { $posts = Post::with('author', 'comments.author', 'community')->where('sold', NULL)->whereBetween('price', array($request->to, $from))->whereIn('community_id', $allCommunities)->where('city_id', $request->city)->paginate(12); } else { $posts = Post::with('author', 'comments.author', 'community')->where('sold', NULL)->whereBetween('price', array($request->to, $from))->where('city_id', $request->city)->paginate(12); } $city = City::where('id', $request->city)->get(); return view('city.home', ['posts' => $posts, 'city' => $city, 'communities' => $communities, 'request' => $requestedInfo]); }
public function showCommunities() { $communities = \App\Community::with('properties')->get(); return view('pages.listCommunities')->with(['communities' => $communities, 'communitySelect' => $this->communitySelect]); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($community, $id) { $post = Post::with('author', 'comments.author', 'community')->where('id', $id)->get(); $comments = Comment::with('author')->where('post_id', $id)->get(); $community = Community::where("id", $community)->get(); $city = City::where('id', $post[0]->city_id)->get(); return view('posts.show', ['post' => $post, "comments" => $comments, 'community' => $community, 'city' => $city]); }
public function __construct() { $this->communities = \App\Community::take(24)->get(); $this->communitySelect = $this->communitiesSelect($this->communities); $this->recent = \App\Property::take(5)->orderBy('id', 'DESC')->with('propertyImages')->get(); }
public function showPosts($community) { $posts = Post::with('author', 'comments.author', 'community')->where('sold', NULL)->orderBy('created_at', 'desc')->where('community_id', $community)->paginate(12); $community = Community::where('id', $community)->get(); return view('community.home', ['posts' => $posts, 'community' => $community]); }