1Here are the complete answer
2
3- Web.php
4
5Route::get('/faq', 'MainController@faq')->name('faq');
6
7Route::any('/faq-search', 'MainController@faqSearch')->name('faqSearch');
8
9- Controller
10
11 public function faq()
12 {
13 $faqs = Faq::paginate(5);
14
15 return view('guest.faq', compact('faqs'));
16 }
17
18 public function faqSearch(Request $request)
19 {
20 $faqSearch = $request->get('faqSearch');
21
22 $faqs = Faq::where('en_question', 'like', $faqSearch.'%')->paginate(5)->setPath('');
23
24 $pagination = $faqs->appends(array(
25 'faqSearch' => $faqSearch
26 ));
27
28 return view('guest.faq', compact('faqs', 'faqSearch'));
29 }
30
31- View (Blade)
32
33 <form action="{{route('faqSearch')}}" method="post">
34 @csrf
35
36 <div class="input-group flex-nowrap">
37 <div class="input-group-prepend">
38 <button class="btn btn-primary input-group-text" type="submit">
39 <i class="fa fa-search"></i>
40 </button>
41 </div>
42 <input type="text" name="faqSearch" class="form-control" placeholder="Search" aria-label="Search" aria-describedby="addon-wrapping" value="{{ old('faqSearch', $faqSearch ?? '') }}" >
43 </div>
44 </form>
45
46 <div class="col-md-3 mx-auto">
47 {{ $faqs->links() }}
48 </div>
49
50
51
52 Thank you so much to "Avinash Nethala"
53
54 Resource
55
56 - https://medium.com/justlaravel/paginated-data-with-search-functionality-in-laravel-ee0b1668b687
57- https://laravel.com/docs/5.3/pagination
1$category = Category::first();
2$apps = $category->apps()->paginate(10);
3return view('example', compact('category', 'apps'));
1Suppose $users is a paginated eloquent collection
2
3$users = User::paginate(10);
4
5You can append attributes to the pagination links;
6
7{{ $users->appends(['sort' => 'votes'])->links() }}
8
9This would result in a url like /users?page=2&sort=votes
10
11You can get the total record count with $users->total()
1@if (isset($paginator) && $paginator->lastPage() > 1)
2
3 <ul class="pagination">
4
5 <?php
6 $interval = isset($interval) ? abs(intval($interval)) : 3 ;
7 $from = $paginator->currentPage() - $interval;
8 if($from < 1){
9 $from = 1;
10 }
11
12 $to = $paginator->currentPage() + $interval;
13 if($to > $paginator->lastPage()){
14 $to = $paginator->lastPage();
15 }
16 ?>
17
18 <!-- first/previous -->
19 @if($paginator->currentPage() > 1)
20 <li>
21 <a href="{{ $paginator->url(1) }}" aria-label="First">
22 <span aria-hidden="true">«</span>
23 </a>
24 </li>
25
26 <li>
27 <a href="{{ $paginator->url($paginator->currentPage() - 1) }}" aria-label="Previous">
28 <span aria-hidden="true">‹</span>
29 </a>
30 </li>
31 @endif
32
33 <!-- links -->
34 @for($i = $from; $i <= $to; $i++)
35 <?php
36 $isCurrentPage = $paginator->currentPage() == $i;
37 ?>
38 <li class="{{ $isCurrentPage ? 'active' : '' }}">
39 <a href="{{ !$isCurrentPage ? $paginator->url($i) : '#' }}">
40 {{ $i }}
41 </a>
42 </li>
43 @endfor
44
45 <!-- next/last -->
46 @if($paginator->currentPage() < $paginator->lastPage())
47 <li>
48 <a href="{{ $paginator->url($paginator->currentPage() + 1) }}" aria-label="Next">
49 <span aria-hidden="true">›</span>
50 </a>
51 </li>
52
53 <li>
54 <a href="{{ $paginator->url($paginator->lastpage()) }}" aria-label="Last">
55 <span aria-hidden="true">»</span>
56 </a>
57 </li>
58 @endif
59
60 </ul>
61
62@endif
63