Reputation: 522
I'm a beginner in Laravel. I have faced a issue in using a PHP array in a SQL statement. I have a array $waypoints
and 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
Reputation: 997
You can always use ->toSql();
to get the query string for debugging.
Upvotes: 1