Skip to content

Commit 9d43d58

Browse files
committed
Merge branch 'develop'
2 parents bfdd413 + a43ff56 commit 9d43d58

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

src/Controllers/BinshopsAdminController.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace BinshopsBlog\Controllers;
44

55
use App\Http\Controllers\Controller;
6+
use BinshopsBlog\Laravel\Fulltext\Search;
7+
use BinshopsBlog\Models\BinshopsCategory;
68
use Carbon\Carbon;
79
use Illuminate\Http\Request;
810
use BinshopsBlog\Interfaces\BaseRequestInterface;
@@ -46,7 +48,6 @@ public function __construct()
4648
}
4749
}
4850

49-
5051
/**
5152
* View all posts
5253
*
@@ -469,4 +470,34 @@ protected function check_if_same_post_exists($slug, $lang_id, $post_id){
469470
return false;
470471
}
471472
}
473+
474+
/**
475+
* Show the search results for $_GET['s']
476+
*
477+
* @param Request $request
478+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
479+
* @throws \Exception
480+
*/
481+
public function searchBlog(Request $request)
482+
{
483+
if (!config("binshopsblog.search.search_enabled")) {
484+
throw new \Exception("Search is disabled");
485+
}
486+
$query = $request->get("s");
487+
$search = new Search();
488+
$search_results = $search->run($query);
489+
490+
\View::share("title", "Search results for " . e($query));
491+
492+
$rootList = BinshopsCategory::roots()->get();
493+
BinshopsCategory::loadSiblingsWithList($rootList);
494+
495+
$language_id = $request->get('language_id');
496+
497+
return view("binshopsblog_admin::index", [
498+
'search' => true,
499+
'post_translations'=>$search_results,
500+
'language_id' => $language_id
501+
]);
502+
}
472503
}

src/Views/binshopsblog_admin/index.blade.php

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

4+
@if($post_translations)
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($post_translations as $post)
16+
@if(isset($post->indexable))
17+
<?php $post = $post->indexable; ?>
18+
@endif
19+
820
<div class="card m-4" style="">
921
<div class="card-body">
1022
<h5 class='card-title'><a class="a-link-cart-color" href='{{$post->url(app('request')->get('locale'))}}'>{{$post->title}}</a></h5>
@@ -91,11 +103,12 @@
91103
</div>
92104
</div>
93105
@empty
94-
<div class='alert alert-warning'>No posts to show you. Why don't you add one?</div>
95-
@endforelse
96-
97-
{{-- <div class='text-center'>--}}
98-
{{-- {{$posts->appends( [] )->links()}}--}}
99-
{{-- </div>--}}
106+
@if(empty($search))
107+
<h5>Manage Blog Posts</h5>
100108

109+
<div class='alert alert-warning'>No posts to show you. Why don't you add one?</div>
110+
@else
111+
<div class='alert alert-warning'>There were no results for this search!</div>
112+
@endif
113+
@endforelse
101114
@endsection

src/routes.php

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

53+
Route::get('/search',
54+
'BinshopsAdminController@searchBlog')
55+
->name('binshopsblog.admin.searchblog');
56+
5357
Route::get('/setup', 'BinshopsAdminSetupController@setup')
5458
->name('binshopsblog.admin.setup');
5559

0 commit comments

Comments
 (0)