AnuradhaH
AnuradhaH

Reputation: 522

Using PHP array in a SQL query in Laravel 5.2

I'm a beginner in Laravel. I have faced a issue in using a PHP array in a SQL statement. I have a array $waypointsand it contains names of cities.

$waypoints = array("Paris", "Moscow", "London","New York");

And i want to find their corresponding city id by a SQL query. Code is as follow.

$cityname = $waypoints[2];

$city = City::where('name', 'LIKE', "$cityname%")->firstOrFail();           

But this query does not get executed. But if i set a string value to variable $cityname manually, it get executed. As example $cityname = "London";. I can't figure out the issue. Help Needed.

Upvotes: 0

Views: 109

Answers (1)

L. Palaiokostas
L. Palaiokostas

Reputation: 997

You can always use ->toSql(); to get the query string for debugging.

Upvotes: 1

Related Questions