I need get js var in view blade file.
I got this one in Controller and got success in console
in route file
Route::post('/some-route', [Controller::class, 'someMethod']);
Route::post('/some-route', 'Controller@someMethod');//this also work
in js file in $(“#applyBonus”).on(“click”, function () method
$.ajax({
url: base_url + '/some-route', // The route to your Laravel controller
type: 'POST',
data: {
someVarName: someInput, // someInput is from blade file input value. got successfully
},
success: function(response) {
console.log(response); //success
alert("ssuccessss___" + someInput); //success
},
error: function(xhr) {
console.error(xhr.responseText);
alert("error___");
}
});
in Controller
public function yourMethod(Request $request) {
//$variable = 'someVarName'; //this also work
$variable = $request->input('someVarName');
//return view('frontend.checkout', compact('variable')); // this also work
//return view('frontend.checkout')->with('variable'); //this also work
return view('frontend.checkout')->with('variableName', $variable);//success in console and alert message
}
and now I tried to get this $variable in view.blade.php
@foreach($variable as $varr) //undefined $variable
<div class="row">{{ $variable }}</div>
<div class="row">{{ $varr }}</div>
@endforeach
or
echo $variable;
//or next. also span tag
<div class="row">{{ $variable }}</div>
and all time I get error – $variable is undefined
with I want do is to get input value as php $variable.
maybe there other to get $variable from input value without page refresh?
or
How get this variable from controller in view blade file?
Thanks
try get input value via input value->js var -> controller -> blade file. on last step get error $variable undefined