[0924b6c] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | namespace App\Http\Controllers\Dashboard;
|
---|
| 4 |
|
---|
| 5 | use App\Models\Post;
|
---|
| 6 | use App\Models\User;
|
---|
| 7 | use App\Models\Comment;
|
---|
| 8 | use App\Http\Controllers\Controller;
|
---|
| 9 |
|
---|
| 10 | class 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 | }
|
---|