Laravel Pagination After Delete: Redirect to Which Page?

Laravel Pagination After Delete: Redirect to Which Page?

Laravel Daily

1 год назад

8,665 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

masud parbhez
masud parbhez - 28.05.2023 22:13

great

Ответить
Murat Alabacak
Murat Alabacak - 26.01.2023 14:40

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

Ответить
Prazen Maharjan
Prazen Maharjan - 17.01.2023 15:31

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 ?

Ответить
Hades inferno
Hades inferno - 17.01.2023 01:46

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

Ответить
KarlSon
KarlSon - 16.01.2023 17:39

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😢.

Ответить
DigitalEagleDev
DigitalEagleDev - 16.01.2023 08:40

💯💯💯

Ответить
Inti Pontt
Inti Pontt - 16.01.2023 01:42

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').

Ответить
Cat Chen
Cat Chen - 15.01.2023 23:29

Thanks, good job. It’s very useful.

Ответить
James Bhatta
James Bhatta - 15.01.2023 19:16

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.

Ответить
hany sabry
hany sabry - 15.01.2023 18:51

don't forget update your chrome :D <3
Thanks for your videos

Ответить
İbrahim
İbrahim - 15.01.2023 17:11

return back(); ?

Ответить
Philip Serefoglou
Philip Serefoglou - 15.01.2023 16:08

Shouldn't paginator take into account that there is no page 4 and automatically redirect to page 3 since this is the last ?

Ответить
Karel Sikyr
Karel Sikyr - 15.01.2023 15:55

redirect()->back() ?

Ответить
Er. Anil Kumar Thakur
Er. Anil Kumar Thakur - 15.01.2023 15:36

shorthand for redirect()->route('users.index',['page'=>$redirectToPage])
can be ...
return to_route('users.index',['page'=>$redirectToPage]); is this wrong

Ответить
shubham sahu
shubham sahu - 15.01.2023 14:22

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..

Ответить
netidpl
netidpl - 15.01.2023 12:26

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.

Ответить
Web Dev
Web Dev - 15.01.2023 11:54

Thank you, Pavilias!
Very useful!

Ответить
Nico Deblauwe
Nico Deblauwe - 15.01.2023 11:01

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.

Ответить
Raziul Islam
Raziul Islam - 15.01.2023 09:55

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

Ответить
drugovic
drugovic - 15.01.2023 09:50

How about when using laravel livewire pagination

Ответить