1 year ago

Laravel Query builder IfElse

Posted 1 year ago by deepu07

Hey folks, Can anyone help me that how to apply if else condition in query builder? for example if my status =1 i want to execute one cond and status !=1 execute other cond. Any help that would be appreciated. Thanks in advance. Here is my query

`//Query Builder

        $this->db->select('id, status, new_class')
        ->from('table1 a')
        ->join('table2 b', ' = a.number')
        ->join('table3 c', 'c.class = a.new_class')
        ->where('', $inputId);

Here if status = 1 i want to stop execution here if status is in [2,3,4] i wanna execute below code too. How can I achieve in laravel query builder.

        ->where_in('status', [ 2, 3, 4 ])
        ->where('b.admin', true)
        ->where('b.teacher', true);
    $results = $this->db->get()->result();

Please sign in or create an account to participate in this conversation.