Good day all, I am trying to count all records in a table but only if the table does not contain data in a specific column (deleted_at). It is a join table the table names are companies and employees. I am currently counting the records with a DB::raw but it should only count it if the deleted_at column is null. Please understand that i am a beginner.
public function index() { $user = Auth::user()->id; $companies = DB::table('companies AS c') ->select([ 'c.id', 'c.logo', 'c.company_name', 'c.created_at', 'c.sector', 'c.deleted_at', DB::raw('COUNT(e.id) AS employee_count') ]) ->leftJoin('employees AS e', 'e.company_id', '=', 'c.id' ) ->leftJoin('company_user AS cu', 'cu.company_id', '=', 'c.id') ->where('cu.user_id', '=', $user) ->where('c.deleted_at', '=', null) ->groupBy('c.id') ->get(); return view('account.companies.index') ->with('companies', $companies); }