/**
  * Display the 5 draft posts of a particular user
  * 
  * @param Request $request
  * @return type
  */
 public function user_posts_draft(Request $request)
 {
     $user = $request->user();
     $posts = Posts::where('author_id', $user->id)->where('active', '0')->orderBy('created_at', 'desc')->paginate(5);
     $title = $user->name;
     return view('home')->withPosts($posts)->withTitle($title);
 }
Esempio n. 2
0
 public function index()
 {
     view()->share('menu_item_active', 'index');
     Title::prepend('Dashboard');
     $data = ['title' => Title::renderr(' : ', true), 'posts_total' => Posts::count(), 'posts_active' => Posts::where('status', 'active')->count(), 'posts_draft' => Posts::where('status', 'draft')->count(), 'posts_moderation' => Posts::where('status', 'moderation')->count(), 'users_total' => Users::count(), 'users_active' => Users::where('active', '1')->count(), 'users_inactive' => Users::where('active', '0')->count(), 'latest_posts' => Posts::active()->orderBy('published_at', 'desc')->limit(5)->get(), 'popular_posts' => Posts::active()->orderBy('views', 'desc')->limit(5)->get()];
     return view('root.dashboard.index', $data);
 }
 public function slug($slug)
 {
     $post = \App\Models\Posts::where("post_slug", $slug)->first();
     $autor = \App\Models\User::where("id", $post->post_autor)->first();
     $categoria = \App\Models\Categorias::where("cat_id", $post->post_categoria_id)->get();
     $posts = $this->pega_posts();
     // Coloca no Thema
     $pagina = view('base.depoimento', compact('post', 'autor', 'categoria', 'posts'));
     return view('themes.layout', compact("pagina"));
 }
Esempio n. 4
0
 public function remove($category_id)
 {
     $category = Categories::find($category_id);
     $category->delete();
     if (Input::get('with_posts', '0') == '1') {
         Posts::where('category_id', $category_id)->delete();
         Notifications::add('Category removed with posts', 'success');
     } else {
         Posts::where('category_id', $category_id)->update(['category_id' => '1']);
         Notifications::add('Category removed. Posts moved to Uncategorized', 'success');
     }
     return Redirect::route('root-categories');
 }
Esempio n. 5
0
 public function myPosts()
 {
     return Posts::where('event_id', '=', $this->id);
 }
Esempio n. 6
0
 public function pega_posts()
 {
     $categoria = \App\Models\Categorias::where("cat_slug", 'noticias')->first();
     $noticias_categoria_id = $categoria->cat_id;
     return \App\Models\Posts::where('post_categoria_id', $noticias_categoria_id)->get();
 }
Esempio n. 7
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($slug)
 {
     $data['post'] = Posts::where('slug', $slug)->first();
     return response()->json($data);
 }
Esempio n. 8
0
 /**
  * DELETANDO TAG || DELETE TAG
  *
  * @param  int  $id
  * @return Response
  */
 public function excluirTags($id)
 {
     $tags_first = Tags::where('tag_id', $id)->first();
     $nova_tag_s = '';
     $tags_array = array();
     if (empty($id)) {
         return 'campovazio';
     } else {
         $posts = Posts::all();
         $tags = array();
         if (count($posts) > 0) {
             foreach ($posts as $post) {
                 if (strpos($post->post_tags, (string) $tags_first->tag_id) != false || $post->post_tags == (string) $tags_first->tag_id) {
                     $tags = explode(",", $post->post_tags);
                     if (count($tags) > 0) {
                         foreach ($tags as $key => $value) {
                             if ($tags_first->tag_id != $value) {
                                 array_push($tags_array, $value);
                             }
                         }
                         $nova_tag_s = implode(",", $tags_array);
                     }
                     //Atualizando as tags
                     Posts::where('post_id', $post->post_id)->update(array('post_tags' => $nova_tag_s));
                     $nova_tag_s = '';
                     $tags_array = array();
                     $tags = array();
                 }
             }
         }
         // Apagando a tag
         if (Tags::where('tag_id', $id)->delete()) {
             return 'sucesso';
         }
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request)
 {
     $post_id = $request->input('post_id');
     $post = Posts::find($post_id);
     if ($post && ($post->author_id == $request->user()->id || $request->user()->is_admin())) {
         $title = $request->input('title');
         $slug = str_slug($title);
         $duplicate = Posts::where('slug', $slug)->first();
         if ($duplicate) {
             if ($duplicate->id != $post_id) {
                 return redirect('edit/' . $post->slug)->withErrors('Title already exists.')->withInput();
             } else {
                 $post->slug = $slug;
             }
         }
         $post->title = $title;
         $post->body = $request->input('body');
         if ($request->has('save')) {
             $post->active = 0;
             $message = 'Post saved successfully';
             $landing = 'edit/' . $post->slug;
         } else {
             $post->active = 1;
             $message = 'Post updated successfully';
             $landing = $post->slug;
         }
         $post->save();
         return redirect($landing)->withMessage($message);
     } else {
         return redirect('/')->withErrors('you have not sufficient permissions');
     }
 }
Esempio n. 10
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $posts = Posts::where('category_id', $id)->cates()->get();
     return response()->json($posts);
 }