Skip to content

Commit a10161c

Browse files
committed
added search on accounts listing page.
1 parent bf8a671 commit a10161c

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

src/Http/Controllers/AccountsController.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ class AccountsController extends AdminBaseController
2424
*/
2525
public function getIndex()
2626
{
27-
$accounts = Account::paginate(10);
27+
$query = Account::orderby('username');
28+
29+
$search = request('q', null);
30+
if( $search )
31+
{
32+
$query->where('username', 'LIKE', "%$search%");
33+
}
34+
35+
$accounts = $query->paginate(10);
2836
return view('Accounts::index', compact('accounts'));
2937
}
3038

src/Views/index.blade.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
@extends("Base::layout")
22

3+
@section('box-header-navbar')
4+
@include('Accounts::partials.searchbar', [
5+
'advancedSearchUrl' => '',
6+
'cancelSearchUrl' => route('accounts.index'),
7+
])
8+
@endsection
9+
310
@section("content")
411
<table class=" table table-hover table-responsive">
512
<thead>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<nav class="navbar navbar-nav">
2+
<div class="container-fluid">
3+
<div class="navbar-header">
4+
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
5+
<span class="sr-only">Toggle navigation</span>
6+
<span class="icon-bar"></span>
7+
<span class="icon-bar"></span>
8+
<span class="icon-bar"></span>
9+
</button>
10+
</div>
11+
<div class="collapse navbar-collapse">
12+
<form method="get" class="sidebar-form col-lg-5">
13+
<div class="input-group">
14+
<input type="text" name="q" value="{{request('q')}}" class="form-control" placeholder="search by username..">
15+
<span class="input-group-btn">
16+
<button type="submit" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i></button>
17+
</span>
18+
</div>
19+
</form>
20+
<!-- /.search form -->
21+
<ul class="nav navbar-nav navbar-right">
22+
<li>
23+
@if( is_null(request('q', NULL)))
24+
<a href="{{ $advancedSearchUrl }}" class="text-purple">
25+
<i class="fa fa-search"></i>&nbsp;
26+
<span>Advanced Search</span>
27+
</a>
28+
@else
29+
<a href="{{ $cancelSearchUrl }}" class="btn btn-danger">
30+
<i class="fa fa-times-circle"></i>&nbsp;
31+
<span>cancel search</span>
32+
</a>
33+
@endif
34+
</li>
35+
</ul>
36+
</div>
37+
</div>
38+
</nav>

0 commit comments

Comments
 (0)