Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vipin93's avatar
Level 13

How to can print user using search filter functionality?

Like I have filter functionality in my app where we can search users in specific year or class but problem is that how can print that like if I search for class Ma and I got total 25 students so how can print them.When I hit print button its print all student instead of only filter student

public function unpaid(Request $request)
{

 $coursewise = $request->course;

 $dt = Carbon::now();

 if ($coursewise)
 {
   $sub = Student::where('status',1)->where('course_id',$coursewise)->whereDoesntHave('subscriptions', function ($query) use($dt) {

          $query->whereMonth('created_at','=',$dt->month);

       })->with('courses')->paginate(15);
 }

 else
 {
   $sub = Student::where('status',1)->whereDoesntHave('subscriptions', function ($query) use($dt) {

          $query->whereMonth('created_at','=',$dt->month);

       })->with('courses')->paginate(15);
 }

 $courses = DB::table("courses")->pluck("name","id");

 if ($request->print)
  {
     $pdf=PDF::loadView('fee.printpdf',compact('sub','courses'));

     return $pdf->stream($sub->student_name. '.' .'pdf');

 }else
 {
    return view('search.search_unpaid',compact('sub','courses'));
 }
0 likes
2 replies
cschoeni's avatar

With which Database Query do you have a problem?

My first ide go like this way:

Student::where('status',1)->where('created_at', [date('Y-m-d', strtotime($dt->month)])-get();
vipin93's avatar
Level 13

@cschoeni its not about query its about print how to pass search data in LoadView. My problem is that when I filter or search students then I got result as my expectation but when I hit the print button its print all students instead of only search or filter students. as u can see in https://datatables.net/extensions/buttons/examples/print/simple.html this if u search and hit print button its only print search result not all

Please or to participate in this conversation.