Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getPhotos #8

Open
wants to merge 4 commits into
base: 3.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/yajra/Zillow/ZillowClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class ZillowClient
protected $results;

/**
* @var array
* @var Illuminate\Support\Collection
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to include illuminate\support on composer if we are going to use collection?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had added it in but when I was testing it resulted in some issues - I'll try to test more later as well as test getPhotos so you can merge

*/
protected $photos = [];
protected $photos = collect();

/**
* @var array - valid callbacks
Expand Down Expand Up @@ -200,13 +200,19 @@ public function __call($name, $arguments)
*/
public function getPhotos($uri)
{
$this->photos = [];
$this->photos = collect();

$client = new GoutteClient;
$crawler = $client->request('GET', $uri);

// Get the latest post in this category and display the titles
$crawler->filter('.photos a')->each(function ($node) {
$this->photos[] = $node->filter('img')->attr('src') ?: $node->filter('img')->attr('href');
$crawler->filter('.photo-tile-image')->each(function ($node) {
$this->photos->push($node->attr('src') ?: $node->filter('img')->attr('href'));
});

// convert url to get a larger image
$this->photos = $this->photos->map(function ($photo) {
return preg_replace('/\/p_c\//', '/p_h/', $photo);
});

$this->response = $this->photos;
Expand Down