Class ‘App\Http\Controllers\DB’ not found in Laravel 5 Controller

DB is not in your current namespace App\Http\Controllers. So you can either import it at the top

use DB;

or precede it with a backslash \DB::table(...). This solves the class not found exception.

You are however not getting a Laravel Collection of Employee models but an array of database rows. Arrays are not objects that have a count() function which results in your final error.

Update: Laravel 5.3 will return a Collection object and not an array. So count() will work on that.

Leave a Comment