How to get data from database by id in laravel 8

How to get data from database by id in laravel 8


In this tutorial, how to get data from database by id in laravel 8, where we will find the single row record from database using laravel eloquent model with find() method. Example given below:

Example 1: 

YourModal::find($id);

Example 2:

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


Demo:

Step 1: Goto Controller and create a edit() function and call Eloquent model ( YourModel.php ) to get data by id from database in laravel.

public function edit($id)
{
  $student = YourModel::find($id);
   return $student;
}

Step 2: create a path in routes/web.php file as follows:

Route::get('get-data/{your_id}', [HomeController::class, 'edit']);


Thanks for reading.