I need to inject some blade logic into my view via an ajax call. I am not sure if this is even possible or if there is an other way?
What I am trying to do:
axios.post('/buildingimage', formData, { headers: {'Content-Type': 'multipart/form-data' }})
.then(response => {
e.preventDefault();
$('.errorMessages').hide();
let building = response.data.building;
let resultInfo = "";
$('.successMessages').show();
let newBuilding = "<tr>" +
" <td>" + building.location + " </td>" +
" <td>" + building.source + "</td>" +
" <td>" + building.disc + "</td>" +
" <td>" + building.result + "</td>" +
" <td>" + resultInfo + "</td>" +
" <td> Edit form </td>" +
" @can('Delete buildings')" +
" <td>" +
" {!! Form::open(['class' => 'deleteBuildingForm', 'method' => 'DELETE', 'route' => ['buildingimage.destroy', " + building.id + "] ]) !!}" +
" <button type='submit' class='btn btn-danger'>" +
" <i class='far fa-trash-alt'></i>" +
" </button>" +
" {!! Form::close() !!}" +
" </td>" +
" @endcan" +
" </tr>";
$(".buildingsTable > tbody:last-child").append(newBuilding);
})
.catch(error => {
if (error.response) {
$('.errorMessages').show();
$('.successMessages').hide();
$.each(error.response.data.errors, function(key, value) {
$('.errorMessagesList').append('<li>' + value + '</li>');
});
}
});
As you can see the form that I try to render isn't actually a form in my view but results in just a string. I am not sure how I can fix this.
The tricky part is that is should be in td of a table.