Skip to main content

Filter Properties by Most Popular Facilities

Premium
8 min read

Now we're getting to the facility filtering. Imagine you search for a property, you have a list, and then you want to have additional filters: swimming pool, pets allowed, etc.

Property search top facilities


Goals of This Lesson

  • Create a DB Structure for Property Facilities
  • Build a list of the most popular facilities - two ways
  • Restructure search results to include facilities
  • Property filter by facility

By the end of this lesson, we will have this test passing in Terminal:

Property search filter by facilities test


New "Type": Property Facilities

Browsing through Booking.com, I realized one more thing: these are all facilities, but they don't belong to the apartments. There are also property facilities, more global things like parking, non-smoking areas, etc...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Peter Sannan avatar

$allfacilities = $properties->pluck('facilities')->flatten();

$facilities = $allfacilities->groupBy('name')->mapWithKeys(function($items, $key){ return [$key => count($items)]; });

maybe a bit more readable to get the count using collection.

Modestas avatar

It really depends on how good you are with collections. Sure, it is almost the same code, but in the end - it's just another way of writing it! So you whatever you see fit :)

WILLY CHANDRA NEGARA avatar
WILLY CHANDRA NEGARA

All my PropertySearchTest.php is failing and the intructions is very unclear. Tried to see the github repo but still failed the test.

PASS Tests\Feature\ApartmentShowTest ✓ apartment show loads apartment with facilities 0.43s

PASS Tests\Feature\AuthTest ✓ can not register with admin role 0.11s ✓ can register with owner role 0.09s ✓ can register with user role 0.10s

PASS Tests\Feature\BookingsTest ✓ user has access to bookings feature 0.09s ✓ property owner does not have access to bookings feature 0.10s

PASS Tests\Feature\PropertiesTest ✓ property owner has access to properties feature 0.09s ✓ user does not have access to properties feature 0.09s ✓ property owner can add property 0.10s

FAIL Tests\Feature\PropertySearchTest ⨯ property search by city returns correct results 0.10s ⨯ property search by country returns correct results 0.10s ⨯ property search by capacity returns correct results 0.10s ⨯ property search by capacity returns only suitable apartments 0.10s

PASS Tests\Feature\PropertyShowTest ✓ property show loads property correctly 0.11s

Modestas avatar

Can you expand a bit on how they fail? What is the error message?

Njuguna Mwangi avatar

The instructions are to add properties to tthe search structure.

For example in the first test in PropertySearchTest, formally we had

$response->assertJsonCount(1)

Right? but now we refactor it to

$response->assertJsonCount(1, 'properties')

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.