Ad

Trying To Extract Goutte Data To View

- 1 answer

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!

Ad

Answer

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]);
}
Ad
source: stackoverflow.com
Ad