planiverse

A minimalist, no-JS front-end for Mastodon.
git clone https://git.mulligrubs.me/planiverse
Log | Files | Refs | README | LICENSE

SearchController.php (1064B)


      1 <?php
      2 
      3 namespace App\Http\Controllers;
      4 
      5 use App\Http\Controllers\Controller;
      6 use Mastodon;
      7 use Illuminate\Http\Request;
      8 
      9 /**
     10  * Controller for search functions.
     11  */
     12 class SearchController extends Controller
     13 {
     14     /**
     15      * Process a search request.
     16      *
     17      * @param Request $request The POST request with search parameters.
     18      *
     19      * @return Illuminate\Routing\Redirector Redirect to the search page.
     20      */
     21     public function search(Request $request)
     22     {
     23         $user = session('user');
     24 
     25         # Verify we have an actual search term.
     26         if ($request->has('search_term'))
     27         {
     28             # Query the search end-point.
     29             $results = Mastodon::domain(env('MASTODON_DOMAIN'))
     30                 ->token($user->token)
     31                 ->get('/search', ['q' => $request->search_term]);
     32 	}
     33         else
     34         {
     35             $results = null;
     36         }
     37 
     38         $vars = [
     39             'results' => $results,
     40             'mastodon_domain' => explode('//', env('MASTODON_DOMAIN'))[1]
     41         ];
     42 
     43         return view('search', $vars);
     44     }
     45 }