source: app/Http/Controllers/Dashboard/IndexController.php@ 0924b6c

Last change on this file since 0924b6c was 0924b6c, checked in by Özkan İliyaz <iliyaz_96@…>, 4 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1<?php
2
3namespace App\Http\Controllers\Dashboard;
4
5use App\Models\Post;
6use App\Models\User;
7use App\Models\Comment;
8use App\Http\Controllers\Controller;
9
10class IndexController extends Controller
11{
12 public function index()
13 {
14 $comments = collect();
15
16
17 if (auth()->user()->hasPermission("approve_all_comments")) {
18 $comments = Comment::where("is_active", false)->get();
19 } else {
20
21 $posts = Post::all();
22 foreach ($posts as $post) {
23 if ($post->user_id == auth()->user()->id) {
24 foreach ($post->comment as $comment) {
25 if (!$comment->is_active) {
26 $comments->push($comment);
27 }
28 }
29 }
30 }
31
32 $comments = $comments->flatten();
33 }
34
35 $counters = array(
36 "allPosts" => Post::count(),
37 "currentUserPosts" => Post::where("user_id", auth()->user()->id)->count(),
38 "users" => User::count(),
39 "total_comments" => Comment::count(),
40 "comments" => auth()->user()->comments->count()
41 );
42
43 return view("dashboard.index")->with([
44 "counters" => $counters,
45 "pendingPosts" => Post::where("is_confirmed", false)->get(),
46 "pendingComments" => $comments,
47 "mostLikedPosts" => Post::where("total_likes", ">=", 1)->orderBy("total_likes", "desc")->take(10)->get(),
48 ]);
49 }
50}
Note: See TracBrowser for help on using the repository browser.