commit d3927063c50803648b5d00dde8963730c3af6900
parent 912929cf02d0ce81a6149514d2729b14b4ea0a33
Author: St John Karp <stjohn@fuzzjunket.com>
Date: Tue, 19 Feb 2019 19:57:20 +0000
Consolidate search logic into one method/route
Put both show search and run search into the same route. This prevents
Lynx from thinking the search results were from a GET request and
caching the contents of the search page.
Diffstat:
3 files changed, 16 insertions(+), 40 deletions(-)
diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php
@@ -12,32 +12,6 @@ use Illuminate\Http\Request;
class SearchController extends Controller
{
/**
- * Show the page that lets users search across Accounts and Statuses.
- *
- * @return Illuminate\View\View The search page.
- */
- public function show_search()
- {
- if (session()->has('results'))
- {
- # The user is coming here after peforming a search.
-
- $results = session('results');
- }
- else
- {
- $results = null;
- }
-
- $vars = [
- 'results' => $results,
- 'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1]
- ];
-
- return view('search', $vars);
- }
-
- /**
* Process a search request.
*
* @param Request $request The POST request with search parameters.
@@ -49,17 +23,23 @@ class SearchController extends Controller
$user = session('user');
# Verify we have an actual search term.
- if (!$request->has('search_term'))
+ if ($request->has('search_term'))
{
- abort(400);
+ # Query the search end-point.
+ $results = Mastodon::domain(env('MASTODON_DOMAIN'))
+ ->token($user->token)
+ ->get('/search', ['q' => $request->search_term]);
}
+ else
+ {
+ $results = null;
+ }
- # Query the search end-point.
- $results = Mastodon::domain(env('MASTODON_DOMAIN'))
- ->token($user->token)
- ->get('/search', ['q' => $request->search_term]);
+ $vars = [
+ 'results' => $results,
+ 'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1]
+ ];
- return redirect()->route('show_search')
- ->with('results', $results);
+ return view('search', $vars);
}
}
diff --git a/resources/views/navigation.blade.php b/resources/views/navigation.blade.php
@@ -3,6 +3,6 @@
<li><a href="{{ route('home') }}">Timeline</a></li>
<li><a href="{{ route('public') }}">Public Timeline</a></li>
<li><a href="{{ route('notifications') }}">Notifications</a></li>
- <li><a href="{{ route('show_search') }}">Search</a></li>
+ <li><a href="{{ route('search') }}">Search</a></li>
</ul>
</nav>
diff --git a/routes/web.php b/routes/web.php
@@ -71,11 +71,7 @@ Route::get('/account/{account_id}/unfollow', 'AccountController@unfollow_account
->name('unfollow')
->middleware('authorize');
-Route::get('/search', 'SearchController@show_search')
- ->name('show_search')
- ->middleware('authorize');
-
-Route::post('/search', 'SearchController@search')
+Route::match(['get', 'post'], '/search', 'SearchController@search')
->name('search')
->middleware('authorize');