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@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
1TarefaController.php
2
3public function index()
4{
5 // $this->validarUser();
6 // backstep store()
7 $user = auth()->user()->id;
8 $tarefas = Tarefa::where('user_id' , $user)->paginate(1);
9 return view('tarefa.index', ['tarefas' => $tarefas]); // tarefa/index.blade.php
10}
11
12views/tarefa/index.blade.php
13
14<nav aria-label="Page navigation example">
15 <ul class="pagination">
16 <li class="page-item">
17 <a
18 class="page-link"
19 href="{{ $tarefas->previousPageUrl() }}">Previous
20 </a>
21 </li>
22
23 @for ($i = 1; $i <= $tarefas->lastPage(); $i++)
24
25 <li class="page-item {{$tarefas->currentPage() == $i ? 'active' : ''}}">
26 <a
27 class="page-link"
28 href="{{ $tarefas->url($i) }}">{{$i}}
29 </a>
30 </li>
31 @endfor
32
33 <li class="page-item">
34 <a class="page-link"
35 href="{{ $tarefas->nextPageUrl() }}">Next
36 </a>
37 </li>
38 </ul>
39</nav>