I'm a beginner in Laravel. I have faced a issue in using a PHP array value inside a SQL query statement.
I have a array $waypoints and it contains names of cities. And var_dump($waypoints) looks like follows.
array (size=4)
0 => string 'Paris' (length=5)
1 => string 'Moscow' (length=6)
2 => string 'London' (length=6)
3 => string 'New York' (length=8)
And I am trying to find the corresponding idof a city by executing a SQL query. The code is as follow.
$cityname = $waypoints[2];
$city = City::where('name', 'LIKE', "$cityname%")->firstOrFail();
This query does not get executed.
var_dump($city) is like this.
string 'select * from 'cities' where 'name' LIKE ? ' (length=42)
But if i set a string value to variable $cityname manually(As example $cityname = "London";), it get executed.
I can't figure out the issue. Help Needed.