Laravel Eloquent Find By Column Query Example

Hello artisan, in this example, we will see laravel find by column name example. We will see how we can get data from database by using a column name. You can use this code in your laravel 5, laravel 6, laravel 7, laravel 8 and laravel 9 version. 

Laravel provides a find() method to find data from the database. With find() method laravel will compare with the id column. Actually not ID, it receives primary key of that model. But if you want to check with another column like name, title, etc. then how you will find by column name? So I am here to show you the below simple examples to find records by column name.

Example code:

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
class DemoController extends Controller
     * Write code on Method
     * @return response()
    public function index(Request $request)
        $user = User::where('name', 'codecheef')->first();


Read also: How to Customize Page Key Name in Laravel Pagination


Hope it can help you.