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:

YourModal::find($id);


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.

YourModal::findOrFail($id);


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

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


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