laravel5.5 使用DB执行sql报错

laravel5.5中使用DB执行select语句时报错,错误如下:

# 代码
public function db()
{
    $user = DB::select('select * from users limit 10');
    dd($user);
}
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Class 'App\Http\Controllers\DB' not found

解决方法,在DB前面加上反斜杠\,代码如下:

public function db()
{
    $user = \DB::select('select * from users limit 10');
    dd($user);
}
# 执行结果
array:1 [▼
  0 => {#219 ▼
    +"id": 1
    +"name": "l93td4Amh7"
    +"email": "2jZEfPTojW<@>laravelcademy.org"
    +"password": "$2y$10$.iL2oCuhpNXKSWVyrPoRFulnc9hPWjTe3vqcZTh5RGQ0QlVMJuZhG"
    +"remember_token": null
    +"created_at": null
    +"updated_at": null
  }
]

你可能感兴趣的:(laravel5.5 使用DB执行sql报错)