Laravel whereRaw, whereIn, whereNotIn, OrderBy

In this laravel tutorial, When we do development, We want to filter some records using laravel inbuild Functions and methods. We would love to share with you many laravel where Function. As we know that laravel provide where, whereDate, whereRaw, whereMonth, whereYear, whereIn, whereNotIn, whereNull, whereNotNull, whereTime, havingRaw, whereBetween, whereNotBetween and laravel pluck.

Lets see the laravel methods :

Where() Function :

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

orWhere() Function :

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

WhereBetween Function :

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

WhereNotBetween Function :

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

WhereIn() Function :

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

WhereNull() Function :

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

WhereNotNull() Function :

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

WhereNotIn() Function :

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

WhereDate() Function :

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

WhereMonth() Function :

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

WhereDay() Function :

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

WhereYear() Function :

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

WhereTime() Function :

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

WhereColumn() Function :

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

WhereRaw() Function :

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

OrderBy Function :

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

SelectRaw() Function :

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

HavingRaw() Function :

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

Laravel Pluck () Function:

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

Laravel Delete () Functions:

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

If you want to know more laravel methods and functions go to https://laravel.com/docs/5.7/queries

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *