skip to Main Content

I was using data table template for frontend. It already have per page and pagination and search. So, how should I do for query. I did like this. I also wanna use search and paginate from template datatable.

public function index() 
{
    $users = User::all();

    return view('users.list', compact('users'));
}

2

Answers


  1. You should customised your code to do so and here you go:

    public function index(Request $request)
    {
        $search = $request->query('search');
    
        $customers = customers::where('name', 'like', "%$search%")
            ->orWhere('email', 'like', "%$search%")
            ->paginate(10);
    
        return view('App.Customer.customerList', compact('customers'));
    }
    
    Login or Signup to reply.
  2. You can use the laravel built-in pagination:

    public function index() 
    {
       $users = User::paginate(15);
    
       return view('users.list', compact('users'));
    }
    

    Then in your view you can loop through your user list and use the pagination links like this:

    {{ $users->links() }}

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search