Laravel Eloquent Where Day, Date, Month, Year, Time, Column

Oct 03, 2022 . Admin



Hello Friends,

In this tutorial, we will go over the demonstration of laravel eloquent where day, date, month, year, time, column. Here you will learn how to use a function in an eloquent query. if you have a question about how to query between two dates using laravel and eloquent then I will give a simple example with a solution. I explained simply step-by-step laravel where a date is a current month code example. You just need to do some steps to do a laravel eloquent tutorial with examples.

Laravel eloquent query methods example; In this tutorial, you will learn laravel eloquents methods like where, whereDate, whereRaw, whereMonth, whereYear, whereIn, whereNotIn, whereNull, whereNotNull, whereTime, havingRaw, whereBetween, whereNotBetween and laravel pluck.

You can use this example with the versions of laravel 6, laravel 7, laravel 8, and laravel 9.

Where() Function

Let’s see the laravel where() eloquent query example; as follows:

DB::table('users')
	->where('id', 1)
	->get();
orWhere() Function

Let’s see the laravel orWhere() eloquent query example; as follows:

DB::table('users')
	->where('id', '>', 100)
	->orWhere('name', 'tutsmake')
	->get();
WhereBetween Function

Let’s see the laravel whereBetween() eloquent query example; as follows:

DB::table('users')
	->whereBetween('id', [1, 100])
	->get();
WhereNotBetween Function

Let’s see the laravel whereNotBetween() eloquent query example; as follows:

DB::table('users')
	->whereNotBetween('id', [1, 100])
	->get();
WhereIn() Function

Let’s see the laravel whereIn() eloquent query example; as follows:

DB::table('users')
	->whereIn('id', [1,2,2,3])
	->get();
WhereNull() Function

Let’s see the laravel whereNull() eloquent query example; as follows:

DB::table('users')
	->whereNull('updated_at')
	->get();
WhereNotNull() Function

Let’s see the laravel whereNotNull() eloquent query example; as follows:

DB::table('users')
	->whereNotNull('updated_at')
	->get();
WhereNotIn() Function

Let’s see the laravel whereNotIn() eloquent query example; as follows:

DB::table('users')
	->whereNotIn('id', [1,2,2,3])
	->get();
WhereDate() Function

Let’s see the laravel whereDate() eloquent query example; as follows:

DB::table('users')
	->whereDate('created_at', date('Y-m-d'))
	->get();
WhereMonth() Function

Let’s see the laravel whereMonth() eloquent query example; as follows:

DB::table('users')
	->whereMonth('created_at', '05')
	->get();
WhereDay() Function

Let’s see the laravel whereDay() eloquent query example; as follows:

DB::table('users')
	->whereDay('created_at', '05')
	->get();
WhereYear() Function

Let’s see the laravel whereYear() eloquent query example; as follows:

DB::table('users')
	->whereYear('created_at', '05')
	->get();
WhereTime() Function

Let’s see the laravel whereTime() eloquent query example; as follows:

DB::table('users')
 	->whereTime('created_at', '=', '1:20:45')
 	->get();
WhereColumn() Function

Let’s see the laravel whereColumn() eloquent query example; as follows:

DB::table('users')
	->whereColumn('first_name', 'last_name')
	->get();
WhereRaw() Function

Let’s see the laravel whereRaw() eloquent query example; as follows:

DB::table('orders')
	->whereRaw('price > IF(state = "TX", ?, 100)', [200])
	->get();
OrderBy Function

Let’s see the laravel orderBy() eloquent query example; as follows:

 DB::table('users')
 	->orderBy('name', 'desc')
 	->get();
SelectRaw() Function

Let’s see the laravel selectRaw() eloquent query example; as follows:

DB::table('orders')
	->selectRaw('price * ? as price_with_tax', [1.0825])
	->get();
HavingRaw() Function

Let’s see the laravel havingRaw() eloquent query example; as follows:

DB::table('orders')
	->select('orders', DB::raw('SUM(price) as total_amount'))
	->groupBy('orders')
	->havingRaw('SUM(price) > ?', [2500])
	->get();
Laravel Pluck () Function

Let’s see the laravel pluck() eloquent query example; as follows:

DB::table('users')
	->where('id', 1)
	->pluck('name');
Laravel Delete () Functions

Let’s see the laravel delete() eloquent query example; as follows:

DB::table('users')
 	->where('id', 1)
 	->delete();

I hope it can help you...

#Laravel