How to WhereIn during array day in laravel

array:23 [▼ 0 => 1 1 => 2 2 => 3 3 => 4 4 => 5 5 => 8 6 => 9 7 => 10 8 => 11 9 => 12 10 => 15 11 => 16 12 => 17 13 => 18 14 => 19 15 => 22 16 => 23 17 => 24 18 => 25 19 => 26 20 => 29 21 => 30 22 => 31 ] 

this is a whole series of working days except Sunday and Saturday, and I have a table of months, and I need Laravel, where is the condition for comparing all data with whe

 ->whereYear('Clock_Day',$yearofdata) ->whereMonth('Clock_Day',$monthofdata) ->whereIn('Clock_Day','=',$workdays) //here can i use something like whereIn->whereday---for comparing all array values and get as per the data 
+5
source share
2 answers

There is no whereDayIn() or similar method, but you can do this:

 ->whereYear('Clock_Day', $yearofdata) ->whereMonth('Clock_Day', $monthofdata) ->where(function($q) use($workdays) { foreach ($workdays as $day) { $q->whereDay('Clock_Day', '=', $day, 'or'); } }) 
+1
source

If Clock_Day is a field in your table, you will need to extract the part of the date that you are comparing for each part (Year, Month, Day). You could use whereIn with DB :: raw:

 ->where(DB::raw('YEAR("Clock_Day")'),$yearofdata) ->where(DB::raw('MONTH("Clock_Day")'),$monthofdata) ->whereIn(DB::raw('DAYOFMONTH("Clock_Day")'),$workdays) 

You must use whereYear or whereMonth to compare these values ​​with the fields in your table named “year” and “month”, but since you want to use the same “Clock_Day” field for all comparisons, you need to extract the corresponding data for each part .

+1
source

Source: https://habr.com/ru/post/1275075/


All Articles