So i'm making a search section for my website but i noticed that my server sees + as a space.
When i search 2 + 2
its /s/2+%2B+2
in url and 2+++2 in server (2 2
when urldecoded) but i want it to be 2 + 2
, how can i achieve that?
// js
$("#searchForm").submit(function(e){
window.location.href = "{{ route('search', ['']) }}/"+encodeURIComponent($("#search").val()).replace(/%20/g, "+");
return false;
});
// web.php
Route::get('/s/{q}', 'Search')->name('search');
// Search controller
public function __invoke(SearchRepository $repo, $query)
{
echo $query;
}