Help with Where in Laravel

Asked

Viewed 214 times

0

Hi, guys wanted a little help from you on a Where.

In my system is like this, I am in the Development photo gallery page( id=1 ), on this page I can register the photos of the month/year of the project ( the stages of the work ). When I register the photos creates a button on the same page with title of month/year ( Ex: December/2014 ) and if you have in January he will register the photos of January/2015. And when I click on this button is to open a modal with the photos referring only to that month/year ( December/2014 ) of the development( id=1).

I managed to do this with Ajax pass the values and return me the photo, but now I have a problem, when I click the button ( December/2014 ), it opens the modal and pulls all photos of the venture with id=1, let’s say I registered ( 8 photos in December/2014 ) and ( 6 photos January/2015 ) he should pull only the 8 photos in December/2014 and not the 14 photos.

Development screen:

Tela do empreendimento

Bench:

Como esta no banco

Ajax code:

$('.requerAjax').click(function(e) {
e.preventDefault();

var resultado = $(this).attr('rel').split('/');
var mes = resultado[0];
var ano = resultado[1];
var categorias_id = resultado[2];

$.ajax({
    type: "POST",
    url: "/admin/empreendimento/fotos-ajax",
    data: { mes: mes, ano: ano, categorias_id: categorias_id }, 
    datatype: 'json',
    beforeSend: function(){
        $(".carregando").show();
    },
    success: function(result){       
        $(".carregando").hide();
        var html = "";
        for (var i = 0; i < result.length; i++) {                
            html += "<img src=" + result[i].imagem + " alt=''>";            
        }
        $( ".modal-body .gallery" ).html(html); 
    }
});

});

Controller code receiving from ajax:

public function postFotosAjax() {
    // $mesAno = Input::all();
    $mes = Input::get('mes');
    $ano = Input::get('ano');
    $id = Input::get('categorias_id');

    if(Request::ajax()){
        $FotosMesAno = DB::table('fotos')
        ->select('mes', 'ano', 'imagem')
        ->where('mes', '=', $mes) // Tem que ser um MES.
        ->where('ano', '=', $ano, 'AND') // Tem que ser um ANO.
        ->where('categorias_id', '=', $id, 'AND') // Tem que ser um ID DO EMPREENDIMENTO.
        ->get();
        return Response::json($FotosMesAno);
    }
}

I explore how it looks on every screen:

  1. Undertaking 1

    • December/2014 ( Photos registered 8 )
    • January/2015 ( Photos posted 6 )
    • February/2015 ( Photos posted 12 )
    • March/2015 ( Photos posted 10 )
    • April/2015 ( Photos posted 8 )
  2. Undertaking 2

    • December/2014 ( Photos registered 20 )
    • January/2015 ( Photos posted 18 )
    • February/2015 ( Photos posted 10 )
    • March/2015 ( Photos posted 19 )

Can anyone help me, to pull the photos of each month/year?

  • 1

    You’re wearing OR categorias_id, but must use AND.

  • Are all AND..

  • 2

    Really just put AND in place the OR. THANK YOU Vinícius and Vagner.

  • You can post the code as text and not as image ?

  • @gmsantos put the code sending via ajax and returning from controller to ajax.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.