我正试图在我的Laravel应用程序中将MySQL数据库转换为RESTful API。我在github偶然发现了这个套餐。
我试过了,并遵循了每一条指令,下面是我的设置:
$args = array(
'name' => 'cacti',
'username' => 'username',
'password' => '****',
'server' => 'localhost',
'port' => 3306,
'type' => 'mysql',
'table_blacklist' => array(),
'column_blacklist' => array()
);
register_db_api( 'dataset-name', $args );这就是我在register_db()上的文章
function register_db( $name = 'cacti', $args = array() ) {
$defaults = array(
'name' => 'cacti',
'username' => 'username',
'password' => '****',
'server' => 'localhost',
'port' => 3306,
'type' => 'mysql',
'table_blacklist' => array(),
'column_blacklist' => array(),
'ttl' => $this->ttl
);
$args = shortcode_atts( $defaults, $args );
$name = $this->slugify( $name );
$this->dbs[$name] = (object) $args;
}我一直得到:
必须选择数据库
我三次检查了我的数据库设置,我为MySQL工作台使用了相同的设置,我可以登录并查看我的数据库。
我错过了什么?
我愿意接受任何有助于我将我的数据库转化为RESTful API的新建议。
发布于 2016-08-10 14:28:18
使用示例时:
$args = array(
'name' => 'cacti',
'username' => 'username',
'password' => '****',
'server' => 'localhost',
'port' => 3306,
'type' => 'mysql',
'table_blacklist' => array(),
'column_blacklist' => array()
);
register_db_api( 'dataset-name', $args );您必须使用url:
/dataset-name/table-name正如其他人所说的,dataset-name不一定要匹配实际的数据库名称。这个名称实际上是数据集名称,它可以是您想要的任何内容。
请注意:请不要使用这个包,因为它在代码中是可怕的,而且似乎没有自动测试。
发布于 2016-08-10 17:35:28
我终于自己做了,在拉勒维尔。
#1 -路线
Route::get('api/psql/{table_name}', 'ApiController@psql');#2 -控制器
public function psql($table_name){
$object = DB::table($table_name)->get();
return $object;
}#3 -称之为
http://localhost:8888/api/psql/users结果
[
{
"id": 2005,
"account_id": "2005",
"email": "test@b",
"fb_email": "",
"tw_email": "",
"created_at": "2016-08-09 11:19:30",
"updated_at": "2016-08-09 11:19:30",
"fb_access_token": "",
"fb_profile_id": "",
"fb_page_id": "",
"fb_username": "",
"auto_provisioning": null,
"service_plan": null
},
{
"id": 2004,
"account_id": "2004",
"email": "test@outlook.com2",
"fb_email": "",
"tw_email": "",
"created_at": "2016-08-08 11:39:50",
"updated_at": "2016-08-09 14:02:55",
"fb_access_token": "",
"fb_profile_id": "",
"fb_page_id": "",
"fb_username": "",
"auto_provisioning": "1",
"service_plan": "Blast"
}
]https://stackoverflow.com/questions/38875995
复制相似问题