Exemplo n.º 1
0
 public function single($id)
 {
     return Post::findOrFail($id);
     /*    	$comments = Comment::select('comments.*', 'users.name')
         		->join('users', 'comments.user_id', '=', 'users.id')
         		->where('post_id', $id)
         		->get();*/
 }
Exemplo n.º 2
0
 public function tagSearch(Request $request)
 {
     $posts = Post::with('tags')->whereRaw("MATCH(title,location,content) AGAINST(? IN BOOLEAN MODE)", array($request->string))->take(20)->get();
     $tags = [];
     foreach ($posts as $post) {
         foreach ($post->tags as $tag) {
             $tags[] = $tag->name;
         }
     }
     $tags = array_unique($tags);
     return $tags;
 }
Exemplo n.º 3
0
 public function store($id, Request $request)
 {
     $validator = Validator::make($request->all(), ['content' => 'required|min:4']);
     if ($validator->fails()) {
         $url = URL::previous() . '#form-link';
         return Redirect::to($url)->withErrors($validator)->withInput();
     }
     $comment = new Comment($request->all());
     $comment->user_id = Auth::user()->id;
     $post = Post::findOrFail($id);
     $post->comments()->save($comment);
     /*      otra opcion: 
             $comment->post_id = $id;
             $comment->save();*/
     session()->flash('report', 'Tu comentario ha sido publicado');
     return redirect()->back();
 }
Exemplo n.º 4
0
 public function postvote(Request $request)
 {
     if (!$request->ajax()) {
         return back();
     }
     $ip = $request->getClientIp();
     $binip = inet_pton($ip);
     $hexip = bin2hex($binip);
     /*$hexip = bin2hex(inet_pton('62.57.188.225'));*/
     if (Postvote::whereRaw("post_id = ? AND HEX(ip_address) = ?", array($request->post_id, $hexip))->count() > 0) {
         return response()->json(['state' => false, 'message' => 'Ya se ha votado desde esta ip']);
     }
     $user_id = Auth::user() ? Auth::user()->id : null;
     $postvote = new PostVote();
     $postvote->post_id = $request->post_id;
     $postvote->user_id = $user_id;
     $postvote->ip_address = $binip;
     $postvote->save();
     $post = Post::find($request->post_id);
     $count = count($post->postvotes);
     $post->up = $count;
     $post->save();
     return response()->json(['state' => true, 'count' => $count]);
 }
Exemplo n.º 5
0
 public function update($id, Request $request)
 {
     $rules = $this->rules($request->all());
     if ($rules['input-multi-dates-format'] == 'error') {
         return Redirect::back()->withInput()->withErrors('hola');
     }
     if ($request->input('datestype') == 'single-date') {
         $datestype = 1;
     } elseif ($request->input('datestype') == 'interval-dates') {
         $datestype = 2;
     } elseif ($request->input('datestype') == 'multi-dates') {
         $datestype = 3;
     } else {
         return Redirect::back()->withInput()->withErrors('hola');
     }
     $this->validate($request, $rules);
     /*cambia con store*/
     $post = Post::find($id);
     $post->title = $request->input('title');
     $post->location = $request->input('location');
     $post->content = $request->input('content');
     $post->lat = $request->input('lat');
     $post->lng = $request->input('lng');
     $post->url = $request->input('url');
     $post->datestype = $datestype;
     $post->user_id = Auth::user()->id;
     $post->save();
     /*cambia con store*/
     Date::where('post_id', $post->id)->delete();
     if ($datestype == 1) {
         $date = new Date();
         $date->post_id = $post->id;
         $datetime = DateTime::createFromFormat('d/m/y', $request->input('input-single-date'));
         $date->date = $datetime->format('Y-m-d');
         $date->save();
     } elseif ($datestype == 2) {
         $date = new Date();
         $datetime = DateTime::createFromFormat('d/m/y', $request->input('input-from-date'));
         $date->post_id = $post->id;
         $date->date = $datetime->format('Y-m-d');
         $date->save();
         $date = new Date();
         $datetime = DateTime::createFromFormat('d/m/y', $request->input('input-to-date'));
         $date->post_id = $post->id;
         $date->date = $datetime->format('Y-m-d');
         $date->save();
     } elseif ($datestype == 3) {
         $dates = array_map('trim', explode(',', $request->input('input-multi-dates')));
         foreach ($dates as $key => $val) {
             $date = new Date();
             $datetime = DateTime::createFromFormat('d/m/y', $val);
             $date->post_id = $post->id;
             $date->date = $datetime->format('Y-m-d');
             $date->save();
         }
     }
     if ($request->input('tags')) {
         foreach ($request->input('tags') as $tagname) {
             $tag = Tag::create(['name' => $tagname]);
             $post->tags()->attach($tag);
         }
     }
     return Redirect::route('single', [$post->id, $post->title]);
 }