Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Search for Property by City or GeoObject

Premium
7 min read

Now, that we have properties in our database, let's start building the search.

Booking.com search by geographical object


Goals of This Lesson

  • Create API endpoint (Route + Controller) for searching the properties by city, country, or geographical object
  • Write PHPUnit tests for all those cases

By the end of this lesson, we will see these tests passing in Terminal:

Property search test


Creating Controller and Route

In later lessons, we will have more parameters for the search, but we have to start somewhere. So, for starters, we will try these criteria:

  • By city
  • By country
  • Close to a geographical object (by its latitude/longitude)

Let's build the controller and method for this...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

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

Already a member? Login here

Comments & Discussion

HN
Huy Nguyen ✓ Link copied!

hi, it seems mysqlite doesn't support acos function because of this error "General error: 1 no such function: acos... "

I have to switch to mysql db to pass the test case

PK
Povilas Korop ✓ Link copied!

I performed my php artisan test on SQLite specifically and it worked for me for some reason.

NS
Ngozi Stephen Onyemauche ✓ Link copied!

Hi, i got the same error that Huy got thesame error while runing the test "General error: 1 no such function: acos... ", what are the alternatives

PK
Povilas Korop ✓ Link copied!

I've googled and I think this StackOverflow may help: acos function in Sqlite

But also, I found this? So maybe it depends on the version of SQLite?

LA
Luis Antonio Parrado ✓ Link copied!

I had the same problem in local machine with sqlite (it doesn't recognize acos trigonometric function)!, i use laragon with Windows, but the tests run successfully in Github Actions on push.

WC
WILLY CHANDRA NEGARA ✓ Link copied!

Any fix for this ? Im using mysql version 8.0.30 got the same error.

AV
Andrea Verrecchia ✓ Link copied!

I'm not clear about something. Why is the search being performed by ID? Shouldn't it be done by like condition on the city/country? Alternatively, is the list displayed to the user when a city is entered into the search input field associated with another route dedicated to autocomplete?

PK
Povilas Korop ✓ Link copied!

Hey Andrea, thanks for the comment. I skipped that part of creating the project, but I assume that on the front-end you have a dropdown of all cities (with autocomplete, yes) and it contains the ID of the city as a value, so that ID is then passed to the API for search.

Probably it should be a separate lesson about API endpoints like /api/cities or /api/geoobjects?keyword=statue, will think about adding such a lesson in the future.