giofrio's avatar

Lumen Blank Screen only on DB:: Query

I just installed a fresh version of Lumen and I'm having an issue with database queries. I have Dotenv, Facades and Eloquent enabled in my app.php file. I've also connected my .env file to my local database.

The site works fine but once I add a query a receive a white blank page (no errors)

Here is my code in my controller

public function index()
    {

        $users = DB::table('users')->get();

                return view('main.home');
    }

Any suggestions?

0 likes
8 replies
bashy's avatar

Blank != no errors.

Check your web server/PHP error logs.

giofrio's avatar

@bashy thanks for the quick response. I am seeing an error in my PHP log. I've placed it below:

[07-May-2015 17:26:14 UTC] PHP Fatal error:  Class 'App\Http\Controllers\DB' not found in /Users/macadmin/Documents/projects/localleader/lumen/app/Http/Controllers/PageController.php on line 11

How do import the DB model?

use App\Http\Controllers\DB
bashy's avatar

Yeah just making sure. That's all you need to do for it to be enabled but I've used Eloquent in mine so not used the DB facade myself.

giofrio's avatar

@bashy I found the issue. It was due to php namespacing which required me to use a \ in front of DB. Below is my working code.

$users = \DB::table('users')->get();
bashy's avatar

Can probably do use DB; at the top and use it without the backslash then!

Please or to participate in this conversation.