Skip to content

Commit

Permalink
Merge pull request #24 from edwardcrompton/feature/17-search-box
Browse files Browse the repository at this point in the history
Feature/17 search box
  • Loading branch information
edwardcrompton authored Mar 14, 2024
2 parents 5099ce1 + 451a104 commit 45b60f3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
10 changes: 8 additions & 2 deletions app/Http/Controllers/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

use App\Models\AudioRecord;
use NominatimLaravel\Content\Nominatim;
use App\Services\UrlLocaliser;

class SearchController extends Controller
{
public function __construct(Nominatim $searchApi) {
protected $searchApi;
protected $urlLocaliser;

public function __construct(Nominatim $searchApi, UrlLocaliser $urlLocaliser) {
$this->searchApi = $searchApi;
$this->urlLocaliser = $urlLocaliser;
}

public function index(string $locale, string $place) {
public function index(string $locale, string $place = '') {

$search = $this->searchApi->newSearch();
$search->query($place)->viewbox(-5.5151, 51.2956, -2.6870, 53.5011);
Expand Down Expand Up @@ -48,6 +53,7 @@ public function index(string $locale, string $place) {
return view('search', [
'place' => $place,
'results' => $list,
'urllocaliser' => $this->urlLocaliser
]);
}
}
8 changes: 1 addition & 7 deletions resources/views/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
<p>{{ __('This list shows the latest audio clips.') }}</p>
<p>{{ __('Search for a place name to add a new audio clip.') }}</p>

<form method="GET" enctype="multipart/form-data" id="placeSearchForm" action="{{ $urllocaliser->route('filter') }}">
@csrf

<label for="place">{{ __('Place name') }}</label>
<input type="text" name="place" id="place" placeholder="{{ __('Search for a place name') }}"></input>
<input type="submit" value="{{ __('Search') }}">
</form>
@include('search-form')

<ul>
@foreach ($audioRecords as $row)
Expand Down
7 changes: 7 additions & 0 deletions resources/views/search-form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<form method="GET" enctype="multipart/form-data" id="placeSearchForm" action="{{ $urllocaliser->route('filter') }}">
@csrf

<label for="place">{{ __('Place name') }}</label>
<input type="text" name="place" id="place" placeholder="{{ __('Search for a place name') }}" value="{{ $place ?? '' }}">
<input type="submit" value="{{ __('Search') }}">
</form>
3 changes: 3 additions & 0 deletions resources/views/search.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

<h1>{{ __('Search') }}</h1>

<h2>{{ __('Results for :place', ['place' => $place]) }}</h2>

@include('search-form')

<ul>
@foreach ($results as $row)
@include('item')
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
return redirect()->route('search', ['place' => $request->place, 'locale' => app()->getLocale()]);
})->name('filter');

Route::get('/search/place/{place}', [SearchController::class, 'index'])
Route::get('/search/place/{place?}', [SearchController::class, 'index'])
->name('search');

Route::get('/audio/record', [AudioController::class, 'record'])
Expand Down

0 comments on commit 45b60f3

Please sign in to comment.