avasssso
avasssso

Reputation: 257

Trying to extract Goutte data to view

I have been working for hours trying to figure out how to extract some data to my view in Laravel.

my controller is as follows:

  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'));
});


    }

and then my view is:

@extends('layouts.app')

@section('content')

@foreach($title as $titles)
<h1>{{$titles}}</h1>
@endforeach


@endsection

any help would be appreciated!

Upvotes: 1

Views: 412

Answers (1)

Daniel Coulbourne
Daniel Coulbourne

Reputation: 36

Assuming the crawler is returning a collection, try something like:

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]);
}

Upvotes: 2

Related Questions