Laravel Livewire how to use whereMonth in blade

44 Views Asked by At

laravel livewire I'm using whereMonth inside foreach but I'm getting error

error

Method Illuminate\Database\Eloquent\Collection::whereMonth does not exist.

My blade

 @foreach ($this->Data as $key=>$Datas) 
                 <tr>
                 <td >
                     >{{$Datas->where('user_id','=',$Datas[0]->user_id) 
                      ->whereMonth('date','=',$this->MonthToNumber)
                      ->where('status','=', 1 )->count() }} 
                  </td>     
             </tr>
 @endforeach
1

There are 1 best solutions below

0
Encoder - Abdukodir Khojiyev On

You can use whereBetween method in your application it might help you

$startDate = Carbon::now()->subMonth(); // Get the date one month ago
$endDate = Carbon::now(); // Get the current date

$data = YourModel::whereBetween('created_at', [$startDate, $endDate])->get();