Комментарии:
great
ОтветитьWhat if we decrease the hidden page value if only one item is available on current page where I hit the delete? If there is just one, hidden page is decreased by 1
Ответитьthe last method doesn't work when we have two records in page 4. It works only when we have one record. How to solve this issue?
$redirectToPage = ( $request->page <= $paginator->lastPage()) always returns false so it always redirects to $paginator->lastPage(); any solution ?
if you specified the number of records to display per page, you would need to also specify it in the destroy method else it would use the default number of 15
ОтветитьWill be video about all staff in laravel 9 + blade but on vue 3 ? For me it is hard to andestud how connect all staff in laravel 9 to vue 3😢.
Ответить💯💯💯
ОтветитьSince you are already redirecting to the 'users.index' route, you can do the 3rd approach in the index method. There is no need to pass a hidden 'page' input either, since the current page can be acquired through the query string with $request->query('page').
ОтветитьThanks, good job. It’s very useful.
ОтветитьI loved 3rd approach but the paginate query may also have some complex conditions. Maybe in the delete form we can check if the total number of records in current page is 1, send the redirectToPage as (currentPage() - 1) and in controller neglect page number if redirectToPage is 0. Just an idea to minimize that extra pagination query mostly with conditions.
Ответитьdon't forget update your chrome :D <3
Thanks for your videos
return back(); ?
ОтветитьShouldn't paginator take into account that there is no page 4 and automatically redirect to page 3 since this is the last ?
Ответитьredirect()->back() ?
Ответитьshorthand for redirect()->route('users.index',['page'=>$redirectToPage])
can be ...
return to_route('users.index',['page'=>$redirectToPage]); is this wrong
Can we talk about elegant way to keep track row number, normally if we goto next page the $loop->index / key again starts from 0 in livewire..
Ответитьpagination should take care of itself so that you can't pass a non-existent page. If we pass the number 100, it should automatically go to the last available page. then assumption number 2 will work.
ОтветитьThank you, Pavilias!
Very useful!
I'm wondering whether it should be the responsibility of the destroy method, or of the index method. In the latter case, you could move the logic of your 3rd solution to index, which solves it for all cases where a non-existent (no longer existing) page is requested, and it takes away one DB query from the loop.
ОтветитьThe best of all is using Ajax (Livewire/InertiaJS) 😁
BTW! 3rd one is the best without ajax and I use min($currentPage, $lastPage) without if/else
How about when using laravel livewire pagination
Ответить