在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
}
]