The following is migration. I want to implement a condition. But I don't know how to check time range between start_time and end_time.
Schema::create('settings', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->time('start_time');
$table->time('end_time');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
following is what I'm trying.
$date = new DateTime("Asia/Karachi");
$date = $date->format('Y-m-d H:i:s');
$date = date('H:i:s',strtotime($date));
$users_with_crypto_only_sms_alert =
User::whereNotNull('device_key')
->where('subscription_package', 'LIKE', '%Morpheus%')
->where('role', '=', 'user')
->where('sms_alerts', '=', 1)
->where('is_email', '=', 0)
->where('is_blocked', '=', 0)
->where('mobile_no', '!=', '')
->whereHas('setting',function($q) use($date){
$q->whereTime('start_time','>=',$date);
$q->whereTime('end_time','<=',$date);
})->pluck('device_key')->all();
dd($users_with_crypto_only_sms_alert);