Laravel 5.5 Method paginate does not exist

When I am trying to put some value in my input search box and after pressing enter button showing above issue.
But when I am trying to filter data with my search button then it’s working fine. so i dig into it. i found one solution on it.

FilterController.php
$users = DB::table('users')
->where(function($query) use ($countryId, $stateId, $cityId) {
	if (isset($countryId) && $countryId !== null && $countryId !== '' && $stateId == 'Select State') {
		$query->where('country_id', '=', $countryId);
	}
	if (isset($countryId) && $countryId !== null && $countryId !== '' && isset($stateId) && $stateId !== 'Select State' && $stateId !== '') {
		$query->where([
							['country_id', '=', $countryId],
							['state_id', '<>', $stateId]
						]);
		
	}
})->get()->paginate(5);

Solution :

Just remove the get() and your code will work fine.

$users = DB::table('users')
->where(function($query) use ($countryId, $stateId, $cityId) {
	if (isset($countryId) && $countryId !== null && $countryId !== '' && $stateId == 'Select State') {
		$query->where('country_id', '=', $countryId);
	}
	if (isset($countryId) && $countryId !== null && $countryId !== '' && isset($stateId) && $stateId !== 'Select State' && $stateId !== '') {
		$query->where([
							['country_id', '=', $countryId],
							['state_id', '<>', $stateId]
						]);
		
	}
})->paginate(5);

References :

  1. Click here
  2. Click here
Chandan Kumar
Tagged : / /