0
Using the Framework Laravel 5.5, How do I call the following route in Ajax?
Route:
Route::group(['prefix' =>'paineladmin', 'namespace' =>'PainelAdmin', ], function(){
Route::post('galeriaArquivos', 'GaleriaimgController@arquivos')->name('galeriaArquivos');
});
Ajax code
function buscar($tamanho){
// repassando as variaveis do php
var pasta = $('#pasta').val();
var tamanho = $tamanho;
// utilizando o split para quebrar o diretorio e receber somente o nome da pasta
var dirimg = pasta.split("/galeriaimg/");
var caminho = '/paineladmin/galeriaimg/arquivos';
var diri = '/images/'+tamanho+'/galeriaimg/';
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var data = {
tamanho: tamanho,
diretorio: dirimg[1],
}
$.ajax({
type: 'POST',
dataType: 'json',
url: caminho,
data:data,
success: function(result){
$.each(result, function(key, value){
var container = '<div class="col-md-4" id="col-'+key+'">';
container += '<div class="img-wrap">';
container += '<img src="'+diri+dirimg[1]+'/'+value+'" class="img-return" alt="galeria" "/>';
container += '<a href="#" class="btn btn-default btn-sm delete" onclick="excluir('+key+')"><i class="fa fa-trash"></i></a>';
container += '</div>';
container += '<input type="hidden" name="imagemgaleria['+key+'][endereco]" value="/galeriaimg/'+dirimg[1]+'/'+value+'" />';
container += '<input type="text" placeholder="Título Imagem" name="imagemgaleria['+key+'][tituloimagem]" class="form-control required inputgaleria" />';
container += '<textarea name="imagemgaleria['+key+'][descricao]" placeholder="Descricao" class="form-control inputgaleria" ></textarea>';
container += '</div>';
$('#galeriaimg').append(container);
});
/* monstrando os botoes que foram ocultados.*/
$('.oculto').show();
$('.group').remove();
}
});
}
I’ve tried calling {{ route('galeriaArquivos') }}
or by following the data from those posts link Stackoverflow
Give a php Artisan route:list and take the correct route.
– Marcos Xavier
@marcosXavier thanks! I did what you went through and I got it solved! It was like this in the file ajax var path = 'galeriaArchives'; hugs,
– Diego Lela
Perfect. I could go into more detail about how you solved it, maybe help someone. I believe that using something like path = {{route(model.galeriaArchives)}} would also work. You would need to see the output of the command I suggested.
– Marcos Xavier