我已经工作了几个小时试图弄清楚如何在Laravel中提取一些数据到我的视图中。
我的控制器如下:
MySqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
outColumn.Add(reader[i].ToString());
}
}
然后我的观点是:
public function practice(Request $request)
{
$client = new Client();
$crawler = $client->request('GET', 'https://www.polkadotpassport.com/');
$crawler->filter('.post-header')->each(function($node){
$title = $node->filter('h2 > a');
return view('flights', compact('title'));
});
}
任何帮助将不胜感激!
答案 0 :(得分:2)
假设crawler
正在返回一个集合,请尝试类似:
public function practice(Request $request)
{
$client = new Client();
$crawler = $client->request(
'GET',
'https://www.polkadotpassport.com/
');
$titles = $crawler->filter('.post-header')->map(function($node){
return $node->filter('h2 > a');
});
return view('flights', ['titles' => $titles]);
}