laravel5怎么在路由中使用数据库查询
展开全部
Route::model('user','User');
Route::get('/hi', function(){
header('content-type:text/html;charset=utf8');
//$rs=DB::select('select * from cf_user limit 0,100');
$rs=User::find();
dd($rs);
//return"hi";
});
数据库:
数据库配置:
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
//'host' => env('DB_HOST', 'localhost'),
'database' => 'test',
//'database' => env('DB_DATABASE', 'forge'),
'username' => 'root',
//'username' => env('DB_USERNAME', 'forge'),
'password' => 'qaz123',
//'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Route::get('/hi', function(){
header('content-type:text/html;charset=utf8');
//$rs=DB::select('select * from cf_user limit 0,100');
$rs=User::find();
dd($rs);
//return"hi";
});
数据库:
数据库配置:
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
//'host' => env('DB_HOST', 'localhost'),
'database' => 'test',
//'database' => env('DB_DATABASE', 'forge'),
'username' => 'root',
//'username' => env('DB_USERNAME', 'forge'),
'password' => 'qaz123',
//'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询