Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how display data in laravel from multiple values id in database with urls

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

Below code definitely work for you.

Route::get('/users/{ids}', function ($ids) {
    $id_array = explode(',', $ids);
    $users = User::whereIn('id', $id_array)->get();
    return $users;
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading