Trying to get property 'image' of non-object 错误请问如何解决呢?
Controller 文件:
public function index(Request $request, Influencers $influencers)
{
$client = new Client([
'timeout' => 20,
'headers' => [
'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0',
// 'proxy' => 'http://46.6.7.212:80',
],
]);
$url = "https://gramho.com/profile/sosann/3177593";
$response = $client->request('GET', $url)->getBody()->getContents();
$crawler = new Crawler();
$crawler->addHtmlContent($response);
$myArray = [];
$myArray['image'] = $crawler->filterXPath("//a/img[@class='post-image']")->extract(array('src'));
$myArray['data'] = $crawler->filterXPath("//div[@class='photo-description']")->extract(['_text']);
// 备注:$crawler->filterXPath("//div[@class='photo-description']")->extract(['_text']); 获得的是数组
return view('admin.influencers.demo',compact('myArray'));
}
以下是用dd($myArray); 的
我想在blande 输出:myArray['image'] 和 myArray['data']
尝试在 blande 写 {{$s->image}} 也报错 Trying to get property 'image' of non-object
<div>
@foreach($myArray as $s)
<span class="badge btn-xs">
{{$s->image}}
</span>
@endforeach
</div>
推荐文章: