laravel check pagination in blade
@if ($items->hasPages())
<div class="pagination-wrapper">
{{ $items->links() }}
</div>
@endif
laravel check pagination in blade
@if ($items->hasPages())
<div class="pagination-wrapper">
{{ $items->links() }}
</div>
@endif
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
paginate relationship laravel7
$category = Category::first();
$apps = $category->apps()->paginate(10);
return view('example', compact('category', 'apps'));
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()
Laravel Pagination
use Illuminate\Pagination\Paginator;
Paginator::useBootstrap();
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
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us