Answers for "php laravel paginate"

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

php laravel paginate

TarefaController.php
  
public function index()
{
  // $this->validarUser();
  // backstep store()
  $user = auth()->user()->id;
  $tarefas = Tarefa::where('user_id' , $user)->paginate(1);
  return view('tarefa.index', ['tarefas' => $tarefas]); // tarefa/index.blade.php
}

views/tarefa/index.blade.php
  
<nav aria-label="Page navigation example">
    <ul class="pagination">
    	<li class="page-item">
  			<a 
  				class="page-link"
  				href="{{ $tarefas->previousPageUrl() }}">Previous
  			</a>
  		</li>

    	@for ($i = 1; $i <= $tarefas->lastPage(); $i++)
    		
  			<li class="page-item {{$tarefas->currentPage() == $i ? 'active' : ''}}">
    			<a 
    				class="page-link" 
    				href="{{ $tarefas->url($i) }}">{{$i}}
  				</a>
    		</li>
    	@endfor
                  
    	<li class="page-item">
        	<a class="page-link" 
               href="{{ $tarefas->nextPageUrl() }}">Next
            </a>
        </li>
    </ul>
</nav>
Posted by: Guest on October-02-2021

Browse Popular Code Answers by Language