When trying to send data from a searchbar form to a route controller the data cannot be reached by using the $request->input(“name”). How can i fix this?
Controller
class SearchController extends Controller
{
function search(Request $request){
if(empty($request->input("search"))){
return view("search", ["results" => [], "searchTerm" => ""]);
}
else{
$searchTerm = $request->input("search");
$papers = Papers::where("title", "like", "%".$searchTerm."%")
->orWhere("author", "like", "%".$searchTerm."%")
->orWhere("tags", "like", "%".$searchTerm."%")
->get();
return view("search", ["results" => $papers, "searchTerm" => $searchTerm])->with("data", $request->input());
}
}
}
Form
<form class="form-search flex-center w100" method="GET" action="{{route("search")}}">
<input type="text" name="search" placeholder="Sök..." value="{{empty($search) ? "" : $search}}">
<button id="submit" for="submit">
<span class="shadow"></span>
<span class="edge"></span>
<span class="front flex-center"><img src="{{asset("svg/search.svg")}}" alt="search icon svg"> Sök</span>
</button>
</form>
Route
use AppHttpControllersLandingController;
use AppHttpControllersSearchController;
use IlluminateSupportFacadesRoute;
Route::get("/", [LandingController::class, "index"])->name("home");
Route::get('/search', [SearchController::class, 'search'])->name('search');
I have tried changing the input to a query and i have used data dumps which gives me “[]” when on the input or query of the request and shows this when on the $request:
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/search"
#requestUri: "/search?search=Repellat+sint+autem+facilis+odit."
#baseUrl: ""
#basePath: null
#method: "GET"
#format: null
#session:
IlluminateSessionSymfonySessionDecorator {#278 ▶}
#locale: null
#defaultLocale: "en"
-preferredFormat: null
-isHostValid: true
-isForwardedValid: true
-isSafeContentPreferred: ? bool
-trustedValuesCache: []
-isIisRewrite: false
#json: null
#convertedFiles: null
#userResolver: Closure($guard = null) {#237 ▶}
#routeResolver: Closure() {#246 ▶}
basePath: ""
format: "html"
New contributor
Lucas Kantola is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.