diff --git a/app/Http/Controllers/FrontIndexController.php b/app/Http/Controllers/FrontIndexController.php index 470af0d..6929ecc 100644 --- a/app/Http/Controllers/FrontIndexController.php +++ b/app/Http/Controllers/FrontIndexController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use App\Models\Location; @@ -13,7 +14,6 @@ class FrontIndexController extends Controller { $locations = Location::where("active", true)->get(); $count = count($locations); - $terms = "no|agenda"; $recent = Location::where("active", true) ->limit(5)->orderByDesc('updated_at')->get(); @@ -26,6 +26,27 @@ class FrontIndexController extends Controller ]); } + public function indexSearch(Request $request) + { + $terms = $request->index_search; + $rawSearch = $terms; + $terms = str_replace(",", "", $terms); + $terms = str_replace(" ", "|", $terms); + $results = DB::select("SELECT * FROM searchlocations('$terms')"); + + $locations = Location::where("active", true)->get(); + $count = count($locations); + $recent = Location::where("active", true) + ->limit(5)->orderByDesc('updated_at')->get(); + + return view('front.index', [ + 'count' => $count, + 'recent' => $recent, + 'title' => "The Bad Space", + 'results' => $results + ]); + } + public function about() { return view('front.about', [ @@ -41,7 +62,7 @@ class FrontIndexController extends Controller $name = $location->name; } return view('front.location', [ - 'title' => $name, + 'title' => str_replace(".", " ", $name), 'location' => $location, 'images' => json_decode($location->images), 'updated' => $location->updated_at->format('Y M d'), diff --git a/resources/views/front/index.blade.php b/resources/views/front/index.blade.php index 5ae28b2..45d407b 100644 --- a/resources/views/front/index.blade.php +++ b/resources/views/front/index.blade.php @@ -8,8 +8,21 @@ + @csrf + @isset($results) +
+
+ + Found {{count($results)}} results: +
+ @foreach($results as $location) + {{$location->name}}
+ @endforeach +
+
+ @endisset
{{$count}} diff --git a/routes/web.php b/routes/web.php index 0b1147c..bf6c1c4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -22,6 +22,7 @@ Route::get("/", [FrontIndexController::class, 'start']); Route::get("/listings/{pageNum}", [FrontIndexController::class, 'listings']); Route::get("/about", [FrontIndexController::class, 'about']); Route::get("/location/{uuid}", [FrontIndexController::class, 'location']); +Route::post("/search", [FrontIndexController::class, 'indexSearch']); //auth Route::get("/login", [AuthController::class, 'showLogin']);