# Laravel Eloquent whereRaw Example

Share Me
•
•
•
•
•
•
•
•
•
•
•

Here today now in this blog, i will show you about laravel db raw where clause. Here i will step by step explain laravel whereraw example. So if you want to see this example of laravel whereraw date_format then i hope you are a right place. Here i will show you laravel eloquent whereraw. just need to follow bellow tutorial step by step of laravel eloquent where db raw.

Now I will give you get to current year and month data in this example . So we can simply use the whereraw in example.

At First of all we will example by using Whereraw(), so let’s see bellow example:

###### Example 1:

SQL Query:

```"select * from `users` where YEAR(created_at) = ?"
```

Laravel Query:

```public function index()
{
\$users = User::whereRaw('YEAR(created_at) = ?', [date('Y')])->get();

dd(\$users);
}```
###### Example 2:

SQL Query:

```"select * from `users` where YEAR(created_at) == ? AND MONTH(created_at) == ?"
```

Laravel Query:

```public function index()
{
\$users = User::whereRaw('YEAR(created_at) == ? AND MONTH(created_at) == ?', [date('Y'),date('m')])->get();

dd(\$users);
}```

Read Also : Laravel Pagination with Ajax Example
{"ft_lang_label":"__label__en","ft_lang_prob":0.7818444,"math_prob":0.8516421,"size":1143,"snap":"2021-31-2021-39","text_gpt3_token_len":296,"char_repetition_ratio":0.15013169,"word_repetition_ratio":0.11956522,"special_character_ratio":0.27734032,"punctuation_ratio":0.16071428,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99471503,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-17T06:42:57Z\",\"WARC-Record-ID\":\"<urn:uuid:b74cf9d3-2827-4ac9-9699-ada9eaaf80e0>\",\"Content-Length\":\"100940\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:dc86fb6e-5880-4afc-b8fd-a3f55e2cafed>\",\"WARC-Concurrent-To\":\"<urn:uuid:fd0aed44-e838-49b0-807f-db35b79553c8>\",\"WARC-IP-Address\":\"174.138.166.212\",\"WARC-Target-URI\":\"https://codingspoint.com/laravel-eloquent-whereraw-example/\",\"WARC-Payload-Digest\":\"sha1:VWPBISQK2IEB45BSJP5MWLGVFGALAZVO\",\"WARC-Block-Digest\":\"sha1:HJMJHAKLVJJOFLOQVJS3IDWHLI46HGRB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780055601.25_warc_CC-MAIN-20210917055515-20210917085515-00620.warc.gz\"}"}