Laravel Livewire: "Load More" Instead of Pagination

Поделиться
HTML-код
  • Опубликовано: 8 сен 2024
  • Quick tip for Laravel Livewire: how to change simple pagination, into "Load more".
    Full Course "Practical Laravel Livewire from Scratch": laraveldaily.t...
    - - - - -
    Try our Laravel QuickAdminPanel: bit.ly/quickad...
    Enroll in my Laravel courses: laraveldaily.t...

Комментарии • 53

  • @sebsobseb
    @sebsobseb 3 года назад +42

    This approach feels inefficient.. I mean, "load more" should technically just load 10 records and add them to the existing list, and not always re-fetch the entire list. Is this possible with Livewire?

    • @kevinmonteza6971
      @kevinmonteza6971 3 года назад

      yeah, i agree, assuming that you have a thousands of records, that might take longer, gonna follow up this, hope there is a proper way

    • @PovilasKorop
      @PovilasKorop 3 года назад +3

      Well, you can load 10 records from the database and add that to the array. But it's still one query to the database each time, maybe a bit more efficient.

    • @hhaassiill
      @hhaassiill 3 года назад

      @@PovilasKorop is it possible to use wire:click on Load More button, then server sends the html for next page data to append to table using js events

    • @PovilasKorop
      @PovilasKorop 3 года назад

      @@hhaassiill not that I know of

    • @tareqabughoush9196
      @tareqabughoush9196 3 года назад +1

      I was gonna comment about this. Yes this is inefficient. If you want to do it the same way he did it in the video, you have to send the offset and the limit will be 10 in that case. Or else you just do a normal pagination but send the pagination next_page_url attribute and obtain the data from there 😉

  • @dimitar2379
    @dimitar2379 3 года назад +11

    Its bad that way, you always get and render all the results 10, 20, 30, 40 etc.. theres no way to make real load-more with livewire.

    • @PovilasKorop
      @PovilasKorop 3 года назад

      Well, you can load 10 records from the database and add that to the array. But it's still one query to the database each time, maybe a bit more efficient.

    • @mokhosh
      @mokhosh 3 года назад

      I guess you can do this when they add wire:append which is on the roadmap

  • @rin.k
    @rin.k 3 года назад +1

    For those who want to add some interactive behaviour, you could emit an event when more data is loaded, then listen for the even using js and scroll to the end of the element.

  • @pavelm89
    @pavelm89 3 года назад +5

    Thank you veryyy veryy much :)

    • @renwar
      @renwar 3 года назад

      Alem am nawa la kurdi ache :)

    • @pavelm89
      @pavelm89 3 года назад +1

      @@renwar lawanaya wabet :)

  • @dinhkhanh
    @dinhkhanh 3 года назад +2

    How about auto-loadmore by scrolling?

  • @arthurminasyan9591
    @arthurminasyan9591 3 года назад

    Thanks. Alternatively:
    Component:
    $model->paginate($this->amount);
    View:
    @if($model->hasMorePages())
    loading button
    @endif

  • @Rawaby2021
    @Rawaby2021 3 года назад

    Thx man, please more wirelive videos ✌🏼

  • @nurlanbabayev6510
    @nurlanbabayev6510 3 года назад

    Thanks from Azerbaijan 🇦🇿

  • @piyushkumardongre5873
    @piyushkumardongre5873 3 года назад

    Hi,
    With Livewire+Bootstrap, I was not able to get to highlight the current selected page in pagination. Your little side note at @1:37 resolved this issue.
    Thanks..

  • @vishamabdulla4895
    @vishamabdulla4895 3 года назад

    I want to know how users with role base can share same controller but content must me different for both role. Need best practice scenario. Example: hrController index show all the information of employee but other hand second role can access basic data of employee.

  • @haskelllisp5998
    @haskelllisp5998 3 года назад

    Super example

  • @Taten210
    @Taten210 3 года назад

    Good video! I have a question, what front end language do you recommend using with Laravel? Vue? Angular? Thanks!

  • @Ali71
    @Ali71 Месяц назад

    Nice

  • @JamesAutoDude
    @JamesAutoDude Год назад

    What I hate about load more is that you can't easily take the user back to where they were before. They'd have to load more again until they are back to where they wanted to be at. Especially for people who like to see the live results right after they save or whatever
    I used to use a website where it would load more upon scrolling down and omg it was so annoying whenever you would edit something and wanted to edit something near it... Had to scroll so many times my finger was sore for just a few items lol

  • @aboodlibda7161
    @aboodlibda7161 3 года назад

    Thanks ❤

  • @gourisankar8809
    @gourisankar8809 3 года назад

    Hey , can you please post a video on how to get the form value of HTML5 editor of bootstrap textarea

  • @adam_devs
    @adam_devs 3 года назад

    need help . my data loads fine but does not render default layout . just plain data

  • @shekhsaifuddin1353
    @shekhsaifuddin1353 3 года назад

    Great.... video

  • @toitespasmoi
    @toitespasmoi 3 года назад

    Anything similar for Inertia ? I even struggle for proper pagination...

  • @zainamin43
    @zainamin43 2 года назад

    Sir, I want scroll to render data automatically like facebook posts in rest api, how can i implement this? I'm sorry for my english is not good

  • @brokersaddatv
    @brokersaddatv 3 года назад

    Can you make a video for a form with image uploading and nested dropdown ( like country , city etc ) ? Also can you make a video for rating and reviews of items/products ?

    • @LaravelDaily
      @LaravelDaily  3 года назад +1

      - Image uploading with Livewire: it is on my to-do list for upcoming weeks, but generally it's all here laravel-livewire.com/docs/2.x/file-uploads
      - Nested dropdown: ruclips.net/video/QoCvntbXvSk/видео.html and ruclips.net/video/pfSjRcudZVA/видео.html - also my component: livewirekit.com/components/parent-child-dependent-dropdowns
      - Rating of products: livewirekit.com/components/livewire-star-rating

    • @brokersaddatv
      @brokersaddatv 3 года назад

      @@LaravelDaily Thanks a ton...

  • @persianabad599
    @persianabad599 3 года назад

    Hi! Thank you for this useful tutorial! Can you please guide me how to hide the button when there is no more record (in your example, 'Users' ) ? Thank a lot!

    • @PovilasKorop
      @PovilasKorop 3 года назад +3

      Well, you would have to calculate the count() of Users in the mount() method probably (or every time on render if you wish) and compare to the number of results. If it's equal - then set some variable like $loadMoreVisible = false; and then in Livewire blade add @if ($loadMoreVisible) ... @endif

    • @persianabad599
      @persianabad599 3 года назад

      @@PovilasKorop Thank you!

  • @vokalout
    @vokalout 3 года назад

    Will the function take() work if there are no records yet in the database?

    • @PovilasKorop
      @PovilasKorop 3 года назад +1

      Yes. It won't throw any errors, if that's what you mean, it will just return empty collection.

    • @vokalout
      @vokalout 3 года назад

      @@PovilasKorop oh okay. I tried it in the past on an empty table, using take(3) and it returned an error because the table is empty. I’ll give it a shot again

  • @neerajsinghtangariya2587
    @neerajsinghtangariya2587 3 года назад

    Hello sir, can you please tell us, After loading all values how can I hide the Load More.. button?

    • @PovilasKorop
      @PovilasKorop 3 года назад

      Answered in another comment: ruclips.net/video/EgjNDZxnJEU/видео.html&lc=UgwpbgSu2fLJcvcDq7d4AaABAg.9G-SEOT9Dtu9G-ya1WAges

    • @neerajsinghtangariya2587
      @neerajsinghtangariya2587 3 года назад

      @@PovilasKorop Got it thank you sir...

  • @overdice2776
    @overdice2776 3 года назад

    How would you hide your Load more button if all users are loaded?

    • @PovilasKorop
      @PovilasKorop 3 года назад

      I implemented it in a component in my recently released Livewire Kit: livewirekit.com/components/livewire-load-more-pagination

  • @amaelftah
    @amaelftah 3 года назад

    thanks a lot, Povilas Korop for sharing that . but I wanted to point an issue regarding this approach and if you have a better solution that would be great to share .
    currently, we have a production app and we implemented the same approach but the page got slower when loading more records.... the reason isn't DB query but it's the payload that livewire returns. for example try to make 3gp slow connection in chrome and seed the db with 1k record and try to load more then check response payload size and check how much time the page takes to parse the returned html.
    so the above problem is livewire problem ... i have made PR a long time ago to address it github.com/livewire/livewire/pull/903 . but unfortunately it didn't got merged .

    • @PovilasKorop
      @PovilasKorop 3 года назад

      Hi, very valid point, and I wouldn't advise using this approach, or Livewire in general, on a bigger size payload. It's a fundamental problem of livewire, re-rendering the whole view which may become quite large.

    • @amaelftah
      @amaelftah 3 года назад

      @@PovilasKorop yes i agree . thanks a lot

    • @jsdeveloper
      @jsdeveloper 3 года назад

      Hi, how do you think about that way to keep rendering only new records while avoiding re-render for already loaded records?

  • @biroman8890
    @biroman8890 3 года назад

    You're the best.
    One small question plz :
    Many people have solid experience in boostrap framework and uses Laravel,
    So, is there a way to have laravel 8 without this tailwind utility ?
    Personally, I use boilerplate 7 : html5boilerplate.com/
    Thanks for your help to the community.

    • @biroman8890
      @biroman8890 3 года назад

      Sorry, The link to version '7' is here : github.com/rappasoft/laravel-boilerplate/releases/tag/v7.2.5

    • @PovilasKorop
      @PovilasKorop 3 года назад

      You can still use Laravel UI, it's based on Bootstrap.

  • @olehtalanov6697
    @olehtalanov6697 3 года назад

    Horrible example((( What if you on 10-th page? 100 or even more records from DB per one time? Maybe $users property and pushing new values to it is better solution?
    And once more: what if no records found for next page?