示例#1
0
 public function store(Post $post, NewCommentRequest $request)
 {
     $data = $request->all();
     $data['ip'] = $_SERVER['REMOTE_ADDR'];
     if (Auth::user()) {
         $data['user_id'] = Auth::user()->id;
         $data['author'] = Auth::user()->name;
         $data['email'] = Auth::user()->email;
     }
     $post->comments()->create($data);
     $redirect = route('posts.show', [$post->id]) . '#comments';
     return redirect($redirect);
 }
示例#2
0
 public function search(Request $request)
 {
     $q = $request->get('q');
     $posts = Post::orWhere('title', 'like', '%' . $q . '%')->orWhere('content', 'like', '%' . $q . '%')->get();
     $locations = Location::orWhere('name', 'like', '%' . $q . '%')->orWhere('address', 'like', '%' . $q . '%')->get();
     return view('admin.admin.search', compact('posts', 'locations'));
 }
示例#3
0
 /**
  * @return mixed
  */
 public function index()
 {
     $notas = Post::all();
     $imgem = asset('img/paris1.jpg');
     $view = view('blog/index')->with('imagem', $imgem)->with(compact('notas'));
     return $view;
 }
示例#4
0
 public static function withTopic($topic)
 {
     $posts = [];
     foreach (Post::orderBy('id', 'desc')->get() as $post) {
         if ($post->topic->slug == $topic) {
             $posts[] = $post;
         }
     }
     return $posts;
 }
示例#5
0
 public function show($slug)
 {
     $posts = Post::withTopic($slug);
     $topic = Topic::where('slug', '=', $slug)->first();
     if ($topic) {
         return view('topics.show')->with(['posts' => $posts, 'topic' => $topic]);
     } else {
         App::abort(404);
     }
 }
示例#6
0
 public function createComment(CommentRequest $req)
 {
     $comment = new Comment();
     $comment->name = $req->input('name');
     $comment->email = $req->input('email');
     $comment->body = $req->input('comment');
     $comment->reply_id = $req->input('reply');
     $post = Post::findorFail($req->input('post_id'));
     $post->comments()->save($comment);
     return redirect()->back();
 }
示例#7
0
 public function deletepost($id)
 {
     if ($id) {
         $id = base64_decode($id);
         $post = \Blog\Post::findOrFail($id);
         $post->update(['post_status' => 'inactive']);
         //->save();
         \Session::flash('delete_post', 'Post has been successfully deleted!');
         return redirect('posts/all');
     }
 }
示例#8
0
 public function show($slug)
 {
     $post = Post::slug($slug);
     if ($post) {
         if ($post->isPublished()) {
             return view('post.show')->with('post', $post);
         } else {
             App::abort(404);
         }
     } else {
         App::abort(404);
     }
 }
示例#9
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Post::truncate();
     factory('Blog\\Post', 10)->create();
     $lastTag = count(Tag::all()) - 1;
     $posts = Post::all();
     foreach ($posts as $post) {
         # code...
         $rand = rand(0, 5);
         for ($i = 1; $i < $rand; $i++) {
             # code...
             $tag = Tag::find(rand(0, $lastTag));
             $post->tags()->attach($tag);
         }
     }
 }
 public function single($id)
 {
     $side = Post::paginate(10);
     $post = Post::find($id);
     return view('posts/single', ['post' => $post, 'side' => $side]);
 }
示例#11
0
 /**
  * @param Post $post
  * @param array $tags
  */
 private function SyncTags(Post $post, array $tags)
 {
     $post->tags()->sync($tags);
 }
示例#12
0
 public function show(Post $post)
 {
     $previous = Post::find($post->id - 1);
     $next = Post::find($post->id + 1);
     return View('posts.show', compact('post', 'previous', 'next'));
 }
示例#13
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($slug)
 {
     $post = Post::where('slug', '=', $slug)->firstorFail();
     $post->delete();
     return redirect('admin/post')->with('message', ['class' => 'success', 'message' => 'Post deleted.']);
 }
 public function post($id)
 {
     $post = Blog\Post::find($id);
     $posts = Blog\Post::all(['id', 'title']);
     return view('posts.post', compact(['post', 'posts']));
 }
示例#15
0
 public function index()
 {
     return view('pages.index')->with(['posts' => Post::latest(5), 'index' => true]);
 }