The route doesn't care about those, so you don't need to add anything in your routes file.
Pagination adding route-parameter to page-links after Model update
Good day Laracons, I am using Route::resources([]) to generate routes, but I realized that I needed the page number from the url query string sent to controller action methods. So, I appended it to the route as query string:
href="{{ route('nationalities.edit', ['nationality' => $nationality?->id, 'page' => Request::query('page', 1)]) }}"
So, the url for edit action method is: http://127.0.0.1:8000/nationalities/19/edit?page=2
However, after updating/editing a record using the route above, I noticed that all paginated links now show http://127.0.0.1:8000/nationalities/19?page=2 - they're all pointing to the url above, which messes up the links.
Thank you for taking precious time out of your busy schedule to read through this question and for looking into the feasibility to solve this puzzle.
Update: The problem is coming from the observer, without the observer, the code works fine. I need the observer to clear and update cache when the model is updated.
Repository Class
class NationalityRepository implements NationalityContract
{
use DataHelper, CacheHelper;
const INDEX_CACHE_KEY = 'nationalities';
const OPTIONS_CACHE_KEY = 'nationalityDropdownOptions';
public function getModels(): mixed
{
$models = new Collection;
try {
$currentPage = $this->getCurrentModelPage();
$models = Cache::rememberForever(self::INDEX_CACHE_KEY . "-page-$currentPage", function () {
$model = resolve(Nationality::class);
return $model?->orderBy('nationality', 'ASC')
?->paginate($model?->getPerPage(), [
'id',
'nationality'
])->withQueryString();
});
} catch (\Throwable $th) {
LogServiceEvent::dispatch(LogLevel::Critical, __CLASS__, __FUNCTION__, $th?->getMessage(), $th?-
>getTrace());
throw $th;
}
return $models;
}
}
Have you tried to use setPath already?
return $model?->orderBy('nationality', 'ASC')
?->paginate($model?->getPerPage(), [
'id',
'nationality'
])->setPath(url('/nationalities'))->withQueryString();
Please or to participate in this conversation.