app/Http/Controllers/QuarterMasterController.php
/*
     * Save quarter office or head of district
     */
Save quarter office or head of district
Save quarter office or head of district
public function store(Request $request){
        try{
            $validator = Validator::make($request->all(), [
                'quarter_name' => 'required',
                'central_office_id' => 'required',
                'formation_office_id' => 'required',
            ]);
            if( $validator->fails()){
                $validatorErrors = [];
                foreach($validator->messages()->getMessages() as $fieldName => $messages) {
                    foreach( $messages as $message){
                        $validatorErrors[$fieldName] = $message;
                    }
                }
                throw new Exception(implode(' ',$validatorErrors));
            }
            $quarterMaster = new QuarterMaster();
            $quarterMaster->quarter_name = $request->input('quarter_name');
            $quarterMaster->central_office_id = $request->input('central_office_id');
            $quarterMaster->formation_office_id = $request->input('formation_office_id');
            $quarterMaster->quarter_details = $request->input('quarter_details');
            if(!$quarterMaster->save())
                throw new Exception("Critical error when save quarter office data!");
            $where = ['quarter_master_id'=>$quarterMaster->id,'role'=>6];
            $quarterMaster->head = TermRelation::findMyAdmin($where);
            return ['success'=>true, 'message'=>'Quarter master office save success', 'data'=>$quarterMaster];
        }catch (Exception $e){
            return ['success'=>false, 'message'=> $e->getMessage()];
        }
    }
public function store ( Request $ request ) { try { $ validator = Validator :: make ( $ request -> all ( ) , [ 'quarter_name' => 'required' , 'central_office_id' => 'required' , 'formation_office_id' => 'required' , ] ) ; if ( $ validator -> fails ( ) ) { $ validatorErrors = [ ] ; foreach ( $ validator -> messages ( ) -> getMessages ( ) as $ fieldName => $ messages ) { foreach ( $ messages as $ message ) { $ validatorErrors [ $ fieldName ] = $ message ; } } throw new Exception ( implode ( ' ' , $ validatorErrors ) ) ; } $ quarterMaster = new QuarterMaster ( ) ; $ quarterMaster -> quarter_name = $ request -> input ( 'quarter_name' ) ; $ quarterMaster -> central_office_id = $ request -> input ( 'central_office_id' ) ; $ quarterMaster -> formation_office_id = $ request -> input ( 'formation_office_id' ) ; $ quarterMaster -> quarter_details = $ request -> input ( 'quarter_details' ) ; if ( ! $ quarterMaster -> save ( ) ) throw new Exception ( " Critical error when save quarter office data! " ) ; $ where = [ 'quarter_master_id' => $ quarterMaster -> id , 'role' => 6 ] ; $ quarterMaster -> head = TermRelation :: findMyAdmin ( $ where ) ; return [ 'success' => true , 'message' => 'Quarter master office save success' , 'data' => $ quarterMaster ] ; } catch ( Exception $ e ) { return [ 'success' => false , 'message' => $ e -> getMessage ( ) ] ; } }
Save quarter office or head of district
Save quarter office or head of district