Guest User

Untitled

a guest
Jan 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. {{ CarbonCarbon::parse($noticia->created_at)->format('d/m/Y') }}
  2.  
  3. namespace AppModels;
  4. use IlluminateDatabaseEloquentModel;
  5. use AppTraitsSluggable;
  6.  
  7. class Post extends Model
  8. {
  9. use Sluggable;
  10. protected static $sluggable = 'titulo';
  11. public static $storage = 'post';
  12. protected $table = 'post';
  13. protected $dates = ['periodo_inicio', 'periodo_fim', 'created_at', 'updated_at'];
  14. protected $fillable = [
  15. 'id', 'titulo', 'conteudo', 'periodo_inicio', 'periodo_fim', 'imagem', 'qtd_views',
  16. 'active', 'destaque', 'slug', 'resumo', 'created_at', 'updated_at', 'title_seo', 'description_seo'
  17. ];
  18. }
  19.  
  20. public function noticiasDetalhe($slug)
  21. {
  22. $base_posts_destaques = Post::where('active', 1)->where('destaque', 1)->orderBy('created_at', 'desc')->take(4)->get();
  23.  
  24. $noticia = Post::where('slug', $slug)->leftjoin('post_rel_categorias', 'post_rel_categorias.post_id', '=', 'post.id')->first();
  25.  
  26. $buscar = '';
  27. $page_title = '';
  28. $page_description = '';
  29.  
  30. if($noticia) {
  31.  
  32. $noticia->update(['qtd_views'=>($noticia->qtd_views + 1)]);
  33. if($noticia->title_seo != "") {
  34. $page_title = $noticia->title_seo . " - Berkan";
  35. } else {
  36. $page_title = $noticia->titulo . " - Berkan";
  37. }
  38.  
  39. if($noticia->description_seo != "") {
  40. $page_description = $noticia->description_seo . " - Berkan";
  41. } else {
  42. $page_description = $noticia->resumo . " - Berkan";
  43. }
  44.  
  45. $categorias = Post_Categoria::where('active', 1)->get();
  46.  
  47. $base_posts = Post::where('post_rel_categorias.post_categoria_id', $noticia->post_categoria_id)
  48. ->where('post_rel_categorias.id', '<>', $noticia->id)
  49. ->leftjoin('post_rel_categorias', 'post_rel_categorias.post_id', '=', 'post.id')
  50. ->select(
  51. 'post_rel_categorias.id',
  52. 'post_rel_categorias.post_id',
  53. 'post.id',
  54. 'post.titulo',
  55. 'post.imagem',
  56. 'post.slug',
  57. 'post.created_at'
  58. )->orderBy('created_at', 'desc')->take(3)->get();
  59.  
  60. } else {
  61. abort(404);
  62. die();
  63. }
  64.  
  65. return view('noticias-detalhe', compact('noticia', 'base_posts_destaques', 'base_posts', 'categorias', 'page_title', 'page_description'));
  66. }
Add Comment
Please, Sign In to add comment