我正在尝试使用laravel在shopify app中进行搜索,但我无法获得结果。当我使用等于运算符时,它工作正常。但是当我使用LIKE运算符时,它无法从获取的数组中获取结果。
$search_blog = $request->search_blog;
$product_id = $request->HDNproductid;
$shop = session('shop');
$sh = App::make('ShopifyAPI');
$app_settings = DB::table('appsettings')->where('id', 1)->first();
$select_store = DB::table('usersettings')->where('store_name', $shop)->get();
$sh = App::make('ShopifyAPI', ['API_KEY' => $app_settings->api_key, 'API_SECRET' => $app_settings->shared_secret, 'SHOP_DOMAIN' => $shop, 'ACCESS_TOKEN' => $select_store[0]->access_token]);
$blog_info = $sh->call(['URL' => '/admin/blogs.json', 'METHOD' => 'GET']);
$blogs_collection = collect($blog_info->blogs);
//$blogs_collection_query = $blogs_collection->where('title', '=', $search_blog);
$blogs_collection_query = $blogs_collection->where('title', 'LIKE', "%".$search_blog."%");
dd($blogs_collection_query);
参见上面的代码,下面是shopify api的$ blog_info变量的结果
{#189 ▼ +"blogs": array:18 [▼
0 => {#190 ▼
+"id": 119668754
+"handle": "test9"
+"title": "blog 2002"
+"updated_at": "2018-01-01T05:05:41-05:00"
+"commentable": "no"
+"feedburner": null
+"feedburner_location": null
+"created_at": "2017-12-30T00:31:17-05:00"
+"template_suffix": null
+"tags": ""
}
1 => {#200 ▼
+"id": 119635986
+"handle": "test8"
+"title": "blog 2003"
+"updated_at": "2018-01-01T05:05:34-05:00"
+"commentable": "no"
+"feedburner": null
+"feedburner_location": null
+"created_at": "2017-12-30T00:30:57-05:00"
+"template_suffix": null
+"tags": ""
}
2 => {#201 ▶}
3 => {#202 ▶}
4 => {#203 ▶}
5 => {#204 ▶}
6 => {#205 ▶}
7 => {#206 ▶}
8 => {#207 ▶}
9 => {#208 ▶}
10 => {#209 ▶}
11 => {#210 ▶}
12 => {#211 ▶}
13 => {#212 ▶}
14 => {#213 ▶}
15 => {#214 ▶}
16 => {#215 ▶}
17 => {#216 ▶} ]}
下面的是$ blogs_collection_query变量的结果。当我使用=运算符时,它将显示以下结果
Collection {#219 ▼ #items: array:1 [▼
17 => {#216 ▼
+"id": 119865362
+"handle": "vbxcvdsf"
+"title": "blog2001"
+"updated_at": "2018-01-03T06:01:44-05:00"
+"commentable": "no"
+"feedburner": ""
+"feedburner_location": ""
+"created_at": "2017-12-30T00:34:33-05:00"
+"template_suffix": null
+"tags": ""
}
] }
当我使用like运算符时,我将结果作为空数组。
Collection {#219 ▼ #items: []}
我该如何解决?