(Laravel) method $ .get can not find route

1

Hey guys, all right?

I would really appreciate your help as I have been stuck with this problem for a couple of days and can not solve it myself.

I have a multi-line table with a checkbox on each line and a button that, when clicked, takes all the rows that are selected, stores the ids of those rows in an array, transforms the array into a json, and makes a request a route by passing this json, where it will be manipulated to go through all the ids and make changes to the database.

Initially it worked quietly, but for a while it stopped working, I do not know why.

JavaScript function (in the view):

    function tornarPendente() {

    var arrayIds = [];

    //pega todos os checkbox que estão selecionados e para cada um pega o ID referente ao aluno
    $.each($('.checkbox1').prop('checked', 'checked'), function() {
        var id = ($(this).attr('id'));
            arrayIds.push(id);  //coloca no vetor de ids
    });

    //converte o array em um json para passar para a rota
    var json = {
        "ids": arrayIds
    };

    $.get('../controle/concluidas/tornarTodasPendentes', json, function(data) {
        window.location.reload(true);
    });

}

Route

Route::get('/controle/concluidas/tornarTodasPendentes/', function() {
$input = Input::only('ids'); //recebe um array de ids
$input = $input['ids']; 
foreach($input as $id) {
    $aluno = new App\Aluno();
    $aluno = $aluno->where('id', '=', $id)->first();
    $aluno->pendente = '1';
    $aluno->save();
}
    return Redirect::back();    

});

NOTE: Strange is the fact that if I change the route address to a route that does not exist, javascript does not return any error (even if I remove the window.location.reaload (true) part) .

NOTE: If I give an alert (json ['ids']) I can see the ids normally.

Is there any way for me to know if these ids have at least reached the route?

Any kind of help is welcome.

Thank you!

    
asked by anonymous 16.02.2016 / 18:45

2 answers

3

Using ../ can cause problems if you are on a route with a sub-segment.

For example,

localhost: 8000 / admin /../ test / 1

It's the same as

 localhost:8000/teste/1

Already in this case:

localhost:8000/admin/acao/../test

The result would be;

localhost:8000/admin/test

In Laravel , because it is an application that is always run in the "root" of your host, it is not necessary to use ../ .

Maybe that's what's causing your problem.

    
17.02.2016 / 14:19
0

It was all a big mess of routes ...

As I said, it occurred after I made a new feature (which was a function to make a select in ascending and descending), which used a / control / pending route / {ascDesc?} that went to the student controllerController @ controlPendents

This made any route in / control / pending / AnyCase go to this controller, including the route that I had created to make them all complete, since the route was: / control / pending / strong>

Now I've changed the route to

/ control / finishVaria , which causes it to fall into the correct controller ...

Thanks so much for your help, for your patience ...

Hugs!

    
18.02.2016 / 04:13