Answers for "pagination in laravel example"

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

custom laravel pagination

@if ($paginator->hasPages())
    <ul class="pager">
       
        @if ($paginator->onFirstPage())
            <li class="disabled"><span>← Previous</span></li>
        @else
            <li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">← Previous</a></li>
        @endif


      
        @foreach ($elements as $element)
           
            @if (is_string($element))
                <li class="disabled"><span>{{ $element }}</span></li>
            @endif


           
            @if (is_array($element))
                @foreach ($element as $page => $url)
                    @if ($page == $paginator->currentPage())
                        <li class="active my-active"><span>{{ $page }}</span></li>
                    @else
                        <li><a href="{{ $url }}">{{ $page }}</a></li>
                    @endif
                @endforeach
            @endif
        @endforeach


        
        @if ($paginator->hasMorePages())
            <li><a href="{{ $paginator->nextPageUrl() }}" rel="next">Next →</a></li>
        @else
            <li class="disabled"><span>Next →</span></li>
        @endif
    </ul>
@endif
Posted by: Guest on May-04-2021
0

pagination in laravel example

//Now you can run and check this example. it is a very simple and basic example.

//If you are using bootstrap then you have to add useBootstrap() on service provider as like bellow:


<?php
  
namespace App\Providers;
  
use Illuminate\Support\ServiceProvider;
use Illuminate\Pagination\Paginator;
  
class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
    
    }
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Paginator::useBootstrap();
    }
}
Posted by: Guest on October-12-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

Code answers related to "pagination in laravel example"

Browse Popular Code Answers by Language