i have a problem, how to get there are multiple in database values.
I used this method it didn’t work :
Route::get('/users/{id}', function ($id) {
$user = User::where('id', [$id])->get();
return $user;
});
I used this method successfully :
Route::get('/users/{id}', function ($id) {
$user = User::where('id', [1, 2])->get();
return $user;
});
i want to display the data i want for example 1,2 or 1,3 or 2,1 inside urls
http://127.0.0.1:8000/users/1,2
http://127.0.0.1:8000/users/1,3
http://127.0.0.1:8000/users/2,1
I’m still a newbie in Laravel, who knows someone can help with my problem. thanks
2
Answers
Below code definitely work for you.
You’re getting the ids as a comma-separated string.
user the above code to convert it to an array then you can get results with multiple users.