Using DB in Middleware Lumen

Asked

Viewed 84 times

0

I am trying to get an instance of the DB class inside my Middleware and is giving the following error:

Class 'DB' not found

public function handle($request, Closure $next) {

    $results = DB::select("SELECT * FROM usuarios");
    var_dump($results);
    return $next($request);

}

How do I use the DB class at this point in the code?

  • ever tried to put a bar in front? With me it works because the autoloader does not search at the root: \DB::select(...)

  • follows the same error

  • Look, it’s certainly the way to class that’s missing. I’ve never used the Lumen, but it shouldn’t be far from it. Check out the documentation: https://lumen.laravel.com/docs/5.4/database

1 answer

0

Add after the class Middleware namespace the following line:

use Illuminate\Support\Facades\DB;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.