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

Thank you read.Hope it will help you. Also follow on facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →