To Avoid Raw Expressions You can use Virtual Columns
1.Add this to your Migration after created_at
column
$table->char('created_at_month',3)->virtualAs('DATE_FORMAT(created_at,"%m")');
Run your Migrations
Now You can Run the following query to get the records that is created at specific month
$months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
$user_date = UserDetails::where('userId', '=', $id)
->whereIn('created_at_month', $months)
->whereYear('created_at', date('Y'))
->pluck('date');
If you want to Know more check the Below links
- https://laravel.com/docs/8.x/migrations#column-modifiers
- https://www.w3schools.com/sql/func_mysql_date_format.asp