strpos() 期望参数 1 是字符串,给定 laravel 5.5 的对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48441599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
strpos() expects parameter 1 to be string, object given laravel 5.5
提问by syed1234
This is my code:
这是我的代码:
public function getLists(Request $request)
{
$user = $request->user()->id;
$apikey = DB::table('apikey')->where('api_key', '=', $user);
if($apikey){
$mc = new MailChimp($apikey);
$mailchimp_ping = $mc->get('lists',['fields' =>
'lists.id,lists.name']);
return Response::json($mailchimp_ping, 200);
}
else
{
$errorResponse = [
'message' => 'Lists not found!',
'error' => '401'
];
return Response::json( $errorResponse);
}
}
I am trying to get mailchimp list based on logged in user id where i am doing wrong? is my where clause expects something else? Any help would be highly appreciated!
我正在尝试根据登录的用户 ID 获取 mailchimp 列表,我做错了什么?我的 where 子句是否期望其他内容?任何帮助将不胜感激!
回答by Alexey Mezenin
Use the value()
method to execute the query and get the key. For example, if a column with key is called apikey
:
使用该value()
方法执行查询并获取密钥。例如,如果调用带有键的列apikey
:
$apikey = DB::table('apikey')->where('api_key', $user)->value('apikey');