浏览代码

Update AccountController

Daniel Supernault 7 年之前
父节点
当前提交
593d532236
共有 1 个文件被更改,包括 16 次插入6 次删除
  1. 16 6
      app/Http/Controllers/AccountController.php

+ 16 - 6
app/Http/Controllers/AccountController.php

@@ -18,15 +18,24 @@ class AccountController extends Controller
     public function notifications(Request $request)
     public function notifications(Request $request)
     {
     {
       $this->validate($request, [
       $this->validate($request, [
-          'page' => 'nullable|min:1|max:3'
+          'page' => 'nullable|min:1|max:3',
+          'a'    => 'nullable|alpha_dash',
       ]);
       ]);
       $profile = Auth::user()->profile;
       $profile = Auth::user()->profile;
+      $action = $request->input('a');
       $timeago = Carbon::now()->subMonths(6);
       $timeago = Carbon::now()->subMonths(6);
-      $notifications = Notification::whereProfileId($profile->id)
-          ->whereDate('created_at', '>', $timeago)
-          ->orderBy('id','desc')
-          ->take(30)
-          ->simplePaginate();
+      if($action && in_array($action, ['comment', 'follow', 'mention'])) {
+        $notifications = Notification::whereProfileId($profile->id)
+            ->whereAction($action)
+            ->whereDate('created_at', '>', $timeago)
+            ->orderBy('id','desc')
+            ->simplePaginate(30);
+      } else {
+        $notifications = Notification::whereProfileId($profile->id)
+            ->whereDate('created_at', '>', $timeago)
+            ->orderBy('id','desc')
+            ->simplePaginate(30);
+      }
 
 
       return view('account.activity', compact('profile', 'notifications'));
       return view('account.activity', compact('profile', 'notifications'));
     }
     }
@@ -105,4 +114,5 @@ class AccountController extends Controller
       }
       }
       return $notifications;
       return $notifications;
     }
     }
+
 }
 }