Blade view helpers compile down to php code. Php is read server side before sending the page to the browser so you can't run php code on the fly. So no.
I suggest using InnerHtml it append your data to the view with JavaScript and HTML.
Hello, it is my first try to use ajax, so if my question is very stupid just write like that :) I want to understand one thing, is possible to return to blade template using ajax values properly. and latter do in blade template @foreach ... @if and so on. What i find out now all response coming back to , that mean that i will nee all my html code write in jquery side or controller, what I would like to avoid. Here is what i have now: Blade view:
<div class="col-md-6">
<label>Plate number</label>
<input type="text" id="plate" class="form-control" name='plate_number' placeholder="Enter your car plate number" required>
<button id='find' class="btn btn-primary pull-right">Find</button>
<div id="result"></div> <!-- in this area i am getting answer from ajax -->
<!-- I would like to see use here values like {{$data['plate_number']}} and so on. -->
<div class="clearfix"></div>
</div>
ajax file:
$("#find").click(function(e){
e.preventDefault();
var plate = $("#plate").val();
$.ajax({
url : "/ajax",
data : 'plate_number='+plate,
success : function(data){
$('#result').html(data);
}
});
});
controller
// Function ajax
public function ajax(Request $request){
if (\Request::ajax()) {
$data = array(Input::get('plate_number'),'Auto','200Eur');
return json_encode($data);
}
}
Sorry for my stupid question and thank you for your help.
@freel In the first place blade generates your first HTML from your view.blade.php executing all the php and blade code, and then this code disappears, it's a server side process. Later, you can use javascript to modify/delete/add your HTML DOM elements based in your AJAX results, which are client side processes.
I know very little about Ajax, so I can't help you with it's processes. It's only to explain you why isn't possible to do what you want in the first instance, you can't do a client side process in a server side process. Take a look at what @jekinney recommended, maybe it can help you.
Please or to participate in this conversation.