[已解决]如何在路由中使用数据库查询?
Route::get('/test',function(){
$rs=DB::select("select * from user limit 100");
var_dump($rs);
});
即可
想问下怎么在路由中使用数据库查询?
我的代码,报错提示 User 类未找到
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', 'WelcomeController@index');
Route::get('home', 'HomeController@index');
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
Route::model('user','User');
Route::get('/user', function(){
header('content-type:text/html;charset=utf8');
//$rs=DB::select('select * from cf_user limit 0,100');
$rs=User::find(1);
dd($rs);
//return "hi";
});
Route::get('/test',function(){
$url = url('/test');
//echo $url;
return "test";
});
Route::get('/reg','UserController@reg');
Route::get('user/{name?}', function($name = null)
{
//abort(404);
return $name;
})->where('name', '[A-Za-z]+');
2 个回复
东东
赞同来自: ty0716
li
赞同来自: