vendredi 25 mars 2016

How to find all conditional both false and true in nested conditional by using PHP and return it to array

I'm create a function to insert and update with many conditional and I want to find out all that conditional both false and true and return it as array to client for checking if some data is missing or can't update or insert.

I've used $return to find out which one conditional is work or not.

  public function trans_issue_till() {

        if (Request::ajax()) {

            $return = [];
            $rule = [
                'till_account_id' => 'required',
                'from_account' => 'required', 
            ];
            $fromacc = Request::input('from_account');
            if ($this->CheckPermId_from_session(90) == true) {
                $fromacc = Request::input('coa_name');
            }
            $data = [
                'till_account_id' => Request::input('till_account_id'),
                'from_account' => $fromacc, 
            ];
            $v = Validator::make($data, $rule);
            if ($v->fails()) {
                $return['form'] = false;
            } else {

                $update = Teller::where('id', '=', $data['till_account_id'])->update(array('balance' => $data['balance']));
                $insert = DB::table('till_transaction')->insert($data);
                if(!$update) {
                    $return['upd_bl'] = false;
                } if(!$insert){
                    $return['ins_trans'] = false;
                }else{
                    $return;
                }
            }
        } else {
            $return['ins_trans'] = 'login';
            return redirect()->route('login');
        }
        foreach($return as $items){
            var_dump($items);
        }
       return $...........
    }

as the final sentence I used foreach for check all the array index which one is true and false after that return to browser.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire