source: app/Http/Controllers/Dashboard/IndexController.php@ 7ed1069

Last change on this file since 7ed1069 was f457265, checked in by Berat Kjufliju <kufliju@…>, 4 years ago

ADD technoweek offer, companies

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[0924b6c]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(),
[f457265]38 "users" => !is_null(auth()->user()->company) ? auth()->user()->company->users->count() : User::count(),
[0924b6c]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.