How to get data filter date according to field table from database
Hi everyone. how to get request data from start_date and end_date according to attendance_absent table from database fields do_date_start and do_date_end? i try to use whereBetween but i get error : Illuminate\Database\Query\Builder::whereBetween(): Argument #2 ($values) must be of type array, string given. how to solve my problem ?
my code in LaporanController.php
class LaporanController extends Controller
{
public function index(Request $request)
{
if (isset($request->start_date) && isset($request->end_date)) {
$start_date = Carbon::parse($request->start_date)->format('Y-m-d');
$end_date = Carbon::parse($request->end_date)->format('Y-m-d');
$attendance_absent = DB::table('attendance_absent as absent')
->whereBetween('absent.do_date_start', 'absent.do_date_end', [$start_date, $end_date])
->get();
dd($attendance_absent);
}
}
}
I've tried that method, when I select from the 14th to the 18th the correct data appears but for example, if I select the 15th to 17th the data becomes null
@SilenceBringer thank you, This method is correct, the data I get, right, but I have a new problem, when I select the 14th and 19th the data is empty, there should be data because on the 14th to 18th the data is in the database.
$attendance_absent = DB::table('attendance_absent as absent')
->whereBetween('absent.do_date_start', [$start_date, $end_date])
->andWhereNull('absent.do_date_end') //If I understand you right
->get();
normally whereBetween using for single column date check. but in this case you need get from the different columns. so try to check those date like this. i think it will we help full for you. do try it like this