ItSolutionStuff.com

Laravel Eloquent Find by Column Name Example

By Hardik Savani • April 16, 2024
Laravel

Hi Guys,

In this example, I will show you how to find records by column name in laravel eloquent.

You can use these tips with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 versions.

By default, laravel provides find() method to find records from the database. with find() method laravel will compare with id column, But if you want to check with another column like name, title, etc. then how you will find by column name? I will show you the below simple examples to find records by column name.

Example 1:

app/Http/Controllers/DemoController.php

<?php

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', 'Hardik Savani')->first();

dd($user);

}

}

Example 2:

app/Http/Controllers/DemoController.php

<?php

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::whereName('Hardik Savani')->first();

dd($user);

}

}

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel 9 One to Many Eloquent Relationship Tutorial

Read Now →

Laravel 9 Eloquent Mutators and Accessors Example

Read Now →

Laravel Eloquent doesntHave() Condition Example

Read Now →

Laravel Eloquent whereHas() Condition Example

Read Now →

Laravel Eloquent When Condition Example

Read Now →

Laravel Eloquent Model Custom Function Example

Read Now →

Laravel Eloquent updateOrCreate Example

Read Now →

Laravel Eloquent firstOrNew Example

Read Now →

Laravel Eloquent whereNotNull() Query Example

Read Now →

Laravel Eloquent selectRaw() Query Example

Read Now →

Multiple orWhere Condition in Laravel Eloquent

Read Now →

How to use Union Query with Laravel Eloquent?

Read Now →

Laravel Has Many Through Eloquent Relationship Tutorial

Read Now →