cyberfly
2/22/2018 - 9:20 AM

Filter collection with where condition

<?php

namespace App\Http\Controllers\Api\V1;

use Illuminate\Http\Request;

class UserNotificationController extends ApiController
{
    public function index(Request $request, $user_id)
    {
      //get collection of user notifications

      $user_notifications = $this->user_notification->latest()->whereUserId($user_id)->get();

      //filter collection with where condition

      $internal_request_count = $notifications->where('notification.notification_type',
            'internal-request')->count();
            
      //we filter from where condition if you need to return all the results, but at the same time you want count by types      
            
    }
}