Laravel Get Data From Database By Id

How to get a record in Laravel by id ?

Use laravel Eloquent find() method to get a record by id in Laravel below is sample usage:


Use Laravel Eloquent findOrFail() method to get data by id. This function operates as If the ID is not found it give you 404 Error.


You can also use first() method with where to get record in laravel by id.

YourModal::where('id',"=", $id)->first();

© Copyright - 2018 - 2023 | All rights reserved at Funda of Web IT