if( isset($request->valve) === "on" )
is not valid
isset($request->valve) evaluates to true or false.
Therefore you are saying true or false === "on"
Try if($request->valve === "on" )
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have the checkbox in my blade search template like this:
{!! Form::checkbox('valve', 'on') !!}
But the checked is not working. I need create the if statement. The statement do something when checkbox will be checked. But this isset construction not working ....
Dump from $request is:
array:2 [▼
"_token" => "f6Pf5Dbv4jvGRoqi7kGBiS5m9ZVDfwu4OdFXarhg"
"valve" => "on"
]
Statement is:
if( isset($request->valve) === "on" ){ ...do something }
if( isset($request->valve) === "on" )
is not valid
isset($request->valve) evaluates to true or false.
Therefore you are saying true or false === "on"
Try if($request->valve === "on" )
By the way, checkboxes that are not checked are not returned in a form response.
You can just check for the existence of the field.
I try this, but doesnt work ...
if( array_key_exists('valve', $request->all()) ){}
What? I'm sure I gave the answer?
If you want to check if it is set then if($request->valve) should work.
but when I used, show:
MethodNotAllowedHttpException
that's nothing to do with this bit of code
in RouteCollection.php line 233
at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 220
at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 533
just check your route
The problem is, that the form is in index.blade.php and this file include search-bar with search input ... route path focus on URL /search ... so when the user search something from url / the form route path is /search ... but search.blade.php include search-bar too ... so when user searching from url /search ... the form is submitted to the /search again... and this is the problem I mean ...
show your form and controller
I used Laravel 5.4, Laravelcollective 5.3. Problem is, that the user searching from URL /search ... form is submitted to /search again ... and this is show error MethodNotAllowed. And the $request->search not contains value ... so SQL show error ....
My form is:
{!! Form::open(['route' => 'contact.search']) !!}
<input type="text" name="search" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-success"><i class="fa fa-search" aria-hidden="true"></i> Search</button>
{!! Form::checkbox('valve', 'on') !!}
{!! Form::close() !!}
My controller is:
public function search( Request $request ){
if($request->valve){
$result = DB::select("SELECT * FROM personals
LEFT JOIN functions ON personals.funkce = functions.id
LEFT JOIN departments ON personals.oddeleni = departments.id
WHERE klapka = $request->search");
}
return view('contacts.search')->withResults($result)
}
<form method="get">
<input type="text" name="search" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-success">
<i class="fa fa-search" aria-hidden="true"></i> Search</button>
<input type="checkbox" name="on"> on
</form>
if($request->valve){
$result = DB::select("SELECT * FROM personals
LEFT JOIN functions ON personals.funkce = functions.id
LEFT JOIN departments ON personals.oddeleni = departments.id
WHERE klapka = $request->search");//here u using where it means if $request is not match the yor klapka it give nothing so here if want search may be empty so use "Orwhere", u can use Elaqaut which very easy
}
By default, a POST method will be assumed try this
Form::open(['route' => 'contact.search', 'metohd' => 'get' ])
its not working ... Please read again ...
index.blade.php contains include search-bar.blade.php, search.blade include search-bar.blade.php too.
From index call function index(), return view('contacts.index') From search call function search(), return view('contacts.search')
Route is
Route::post('/search' , 'ContactController@search') ->name('contact.search');
The problem is, that user search from url / .... index() form is submitted via POST method to the url /search ... but when user again search .. searched from /search no / .. so form is submitted to /search ... this I need fix it ... another i see MethodNotAllowed
why u using another view
I dont know, I need the search form still via top of the page ... in each page ..
What does your routes/web.php look like?
Route::get('/' , 'ContactController@index') ->name('contact.index');
Route::post('/search' , 'ContactController@searchresults') ->name('contact.search');
Create a new partial and put this in it;
<form method="post", action="{{ route('contact.search') }}" >
{{ csrf_field() }}
<input type="text" name="search" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-success"><i class="fa fa-search" aria-hidden="true"></i> Search</button>
<input type="checkbox" name="valve "value="on" />
</form>
Then include the partial in your master layout.
You should now have the form at the top of every page that uses the master layout
You can then fill in the form and press submit. It will follow your route and go to your ContactController with $request->search and $request->valve passed over.
You then do the search and render the search results.
Please or to participate in this conversation.