NotificationController.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Http\Controllers\Account;
  3. use App\Models\Notification;
  4. use Illuminate\Http\Request;
  5. use App\Http\Requests;
  6. use App\Http\Controllers\Controller;
  7. use Illuminate\Support\Facades\Auth;
  8. use Illuminate\Support\Facades\Config;
  9. class NotificationController extends Controller
  10. {
  11. /**
  12. * 显示用户通知
  13. *
  14. * @return \Illuminate\Http\Response
  15. */
  16. public function getIndex(Request $request)
  17. {
  18. $notifications = Notification::where('to_user_id',$request->user()->id)->orderBy('created_at','DESC')->paginate(12);
  19. $notifications->map(function($notification){
  20. $notification->type_text = Config::get('tipask.notification_types.'.$notification->type);
  21. });
  22. $this->readNotifications(0,'user');
  23. return view('theme::notification.index')->with('notifications',$notifications);
  24. }
  25. public function getReadAll()
  26. {
  27. Notification::where('to_user_id','=',Auth()->user()->id)->where('is_read','=',0)->update(['is_read'=>1]);
  28. return $this->success(route('auth.notification.index'),'设置成功');
  29. }
  30. }