gear
Image not found

How to filter data with date | How to get data with date

Comment (0)

Admin


Hey Developer,

To day i show you How to filter data with date | How to get data with date . Laravel Datatables Date Range Filter Example

 

Example 1:

public function index(Request $request)
{
  this->validate($request,[
   'start_date' => 'required|date',
   'end_date' => 'required|date|before_or_equal:start_date',
  ]);

  $start = Carbon::parse($request->start_date);
  $end = Carbon::parse($request->end_date);

  $get_all_user = User::whereDate('date','<=',$end->format('m-d-y'))
  ->whereDate('date','>=',$start->format('m-d-y'));

  return view('userPage.index', compact('get_all_user'));
}

 

Example 2:

public function index(Request $request)
 {   

        $payments = '';
        $query    = Payment::orderBy('id','DESC')->where('section_id',$section);

        $from_date = $request->from_date;
        $to_date = $request->to_date;

        if ($from_date && $to_date) {
            $query->whereBetween('date', [$request->from_date, $request->to_date]);
        }

        $payments = $query->get();

        return view('admin.payment.index',compact('payments','from_date','to_date'));
 }

 

I hope it will help you.....

Any confution please comment...

Thanks 


Others Problem Fix Stroy



Comments (0)

Your Comment