Skip to content

Commit 53b2764

Browse files
committed
feat: admin post search
1 parent a2d8ef6 commit 53b2764

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

src/Controllers/BinshopsBlogAdminController.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,28 @@ protected function processUploadedImages(BaseRequestInterface $request, Binshops
227227
]);
228228
}
229229
}
230+
231+
/**
232+
* Show the search results for $_GET['s']
233+
*
234+
* @param Request $request
235+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
236+
* @throws \Exception
237+
*/
238+
public function search(Request $request)
239+
{
240+
if (!config("binshopsblog.search.search_enabled")) {
241+
throw new \Exception("Search is disabled");
242+
}
243+
$query = $request->get("s");
244+
$search = new Search();
245+
$search_results = $search->run($query);
246+
247+
\View::share("title", "Search results for " . e($query));
248+
249+
return view("binshopsblog_admin::index", [
250+
'search' => true,
251+
'posts'=>$search_results
252+
]);
253+
}
230254
}

src/Views/binshopsblog_admin/index.blade.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
@extends("binshopsblog_admin::layouts.admin_layout")
22
@section("content")
33

4+
@if($posts)
5+
<div class='search-form-outer mb-3'>
6+
<form method='get' action='{{route("binshopsblog.admin.searchblog", app('request')->get('locale'))}}' class='text-center'>
7+
<input style="display: inline-block; width: 50%" type='text' name='s' placeholder='Search...' class='form-control' value='{{\Request::get("s")}}'>
8+
<input style="display: inline-block" type='submit' value='Search' class='btn btn-primary m-2'>
9+
</form>
10+
</div>
411

5-
<h5>Admin - Manage Blog Posts</h5>
12+
<h5>Manage Blog Posts</h5>
13+
@endif
614

715
@forelse($posts as $post)
16+
@if(isset($post->indexable))
17+
<?php $post = $post->indexable; ?>
18+
@endif
819
<div class="card m-4" style="">
920
<div class="card-body">
1021
<h5 class='card-title'><a class="a-link-cart-color" href='{{$post->url()}}'>{{$post->title}}</a></h5>
@@ -91,7 +102,13 @@
91102
</div>
92103
</div>
93104
@empty
94-
<div class='alert alert-warning'>No posts to show you. Why don't you add one?</div>
105+
@if(empty($search))
106+
<h5>Manage Blog Posts</h5>
107+
108+
<div class='alert alert-warning'>No posts to show you. Why don't you add one?</div>
109+
@else
110+
<div class='alert alert-warning'>There were no results for this search!</div>
111+
@endif
95112
@endforelse
96113

97114

@@ -101,4 +118,4 @@
101118
</div>
102119

103120

104-
@endsection
121+
@endsection

src/routes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
/* Admin backend routes - CRUD for posts, categories, and approving/deleting submitted comments */
4343
Route::group(['prefix' => config('binshopsblog.admin_prefix', 'blog_admin')], function () {
4444

45+
Route::get('/search',
46+
'BinshopsAdminController@searchBlog')
47+
->name('binshopsblog.admin.searchblog');
48+
4549
Route::get('/', 'BinshopsBlogAdminController@index')
4650
->name('binshopsblog.admin.index');
4751

0 commit comments

Comments
 (0)