Answers for "Laravel Pagination"

PHP
3

laravel pagination and post

Here are the complete answer 
  
- Web.php
  
Route::get('/faq', 'MainController@faq')->name('faq');

Route::any('/faq-search', 'MainController@faqSearch')->name('faqSearch');

- Controller
  
      public function faq()
    {
        $faqs = Faq::paginate(5);

        return view('guest.faq', compact('faqs'));
    }

    public function faqSearch(Request $request)
    {
        $faqSearch = $request->get('faqSearch');

        $faqs = Faq::where('en_question', 'like', $faqSearch.'%')->paginate(5)->setPath('');

        $pagination = $faqs->appends(array(
          'faqSearch' => $faqSearch
        ));

        return view('guest.faq', compact('faqs', 'faqSearch'));
    }

- View (Blade)
  
            <form action="{{route('faqSearch')}}" method="post">
              @csrf

                <div class="input-group flex-nowrap">
                    <div class="input-group-prepend">
                        <button class="btn btn-primary input-group-text" type="submit">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>
                    <input type="text" name="faqSearch" class="form-control" placeholder="Search" aria-label="Search" aria-describedby="addon-wrapping" value="{{ old('faqSearch', $faqSearch ?? '') }}" >
                </div>
            </form>
  
              <div class="col-md-3 mx-auto">
                {{ $faqs->links() }}
            </div>


  
 Thank you so much to "Avinash Nethala"
  
  Resource
  
  - https://medium.com/justlaravel/paginated-data-with-search-functionality-in-laravel-ee0b1668b687
- https://laravel.com/docs/5.3/pagination
Posted by: Guest on August-14-2021
3

paginate relationship laravel7

$category = Category::first();
$apps = $category->apps()->paginate(10);
return view('example', compact('category', 'apps'));
Posted by: Guest on July-11-2020
3

laravel pagination with get parameters

Suppose $users is a paginated eloquent collection

$users = User::paginate(10);

You can append attributes to the pagination links;

{{ $users->appends(['sort' => 'votes'])->links() }}

This would result in a url like /users?page=2&sort=votes

You can get the total record count with $users->total()
Posted by: Guest on November-22-2020
0

laravel pagination

DB::table('users') -> paginate(15)
Posted by: Guest on April-30-2021
1

Laravel Pagination

@if (isset($paginator) && $paginator->lastPage() > 1)

    <ul class="pagination">

        <?php
        $interval = isset($interval) ? abs(intval($interval)) : 3 ;
        $from = $paginator->currentPage() - $interval;
        if($from < 1){
            $from = 1;
        }

        $to = $paginator->currentPage() + $interval;
        if($to > $paginator->lastPage()){
            $to = $paginator->lastPage();
        }
        ?>

        <!-- first/previous -->
        @if($paginator->currentPage() > 1)
            <li>
                <a href="{{ $paginator->url(1) }}" aria-label="First">
                    <span aria-hidden="true">«</span>
                </a>
            </li>

            <li>
                <a href="{{ $paginator->url($paginator->currentPage() - 1) }}" aria-label="Previous">
                    <span aria-hidden="true">‹</span>
                </a>
            </li>
        @endif

        <!-- links -->
        @for($i = $from; $i <= $to; $i++)
            <?php 
            $isCurrentPage = $paginator->currentPage() == $i;
            ?>
            <li class="{{ $isCurrentPage ? 'active' : '' }}">
                <a href="{{ !$isCurrentPage ? $paginator->url($i) : '#' }}">
                    {{ $i }}
                </a>
            </li>
        @endfor

        <!-- next/last -->
        @if($paginator->currentPage() < $paginator->lastPage())
            <li>
                <a href="{{ $paginator->url($paginator->currentPage() + 1) }}" aria-label="Next">
                    <span aria-hidden="true">›</span>
                </a>
            </li>

            <li>
                <a href="{{ $paginator->url($paginator->lastpage()) }}" aria-label="Last">
                    <span aria-hidden="true">»</span>
                </a>
            </li>
        @endif

    </ul>

@endif
Posted by: Guest on April-30-2021
0

Laravel Pagination

use Illuminate\Pagination\Paginator;

Paginator::useBootstrap();
Posted by: Guest on September-08-2021

Code answers related to "Laravel Pagination"

Browse Popular Code Answers by Language