app/Http/Controllers/Admin/SubCategoriesController.php
// STORE SUB CATEGORY CREATION FORM DATA
STORE SUB CATEGORY CREATION FORM DATA
STORE SUB CATEGORY CREATION FORM DATA
public function save(SubCateRequest $request)
    {
        try {
            $cateBags = collect($request->cate_bags);
            $defLangCate = $cateBags->filter(function ($val, $key)
            {
                $defLang = getDefaultLang();
                $key = 'cate_abbr';
                return $val[$key] == $defLang;
            });
            $defLangCateDetails = array_values(
                $defLangCate->all()
            )[0];
            if ($request->has('cate_imag')) {
                $imgPath = uploadFile(
                    'sub_cates',
                    $request->cate_imag
                );
            } else {
                $imgPath = '';
            }
            DB::beginTransaction();
            $defLangCateID = SubCate::insertGetId([
                'trans_lang'    => strtoupper($defLangCateDetails['cate_abbr']),    
                'trans_of'      => 0,                                               
                'name'          => ucfirst($defLangCateDetails['cate_name']),       
                'slug'          => $defLangCateDetails['cate_name'],                
                'photo'         => $imgPath,                                        
                'cate_id'       => $request->input('main_cate'),                    
                'status'        => $defLangCateDetails['cate_stat']                 
            ]);
            $restLangsCate = $cateBags->filter(function ($val, $key)
            {
                $defLang = getDefaultLang();
                $key = 'cate_abbr';
                return $val[$key] != $defLang;
            });
            if (isset($restLangsCate) && $restLangsCate->count() > 0) {
                $restLangsCateData = [];
                foreach ($restLangsCate as $restLangCate) {
                    $restLangsCateData[] = [
                        'trans_lang'    => strtoupper($restLangCate['cate_abbr']),      
                        'trans_of'      => $defLangCateID,                              
                        'name'          => ucfirst($restLangCate['cate_name']),         
                        'slug'          => $restLangCate['cate_name'],                  
                        'photo'         => $imgPath,                                    
                        'cate_id'       => $request->input('main_cate'),                
                        'status'        => $restLangCate['cate_stat']                   
                    ];
                }
                SubCate::insert($restLangsCateData);
            }
            DB::commit();
            return redirect()->route('admin.sub.cates')->with([
                'success' => 'Stored Successfully'
            ]);
        } catch (\Throwable $th) {
            DB::rollback();
            return redirect()->route('admin.sub.cates')->with([
                'error' => 'Something went terribly wrong'
            ]);
        }
    }
public function save ( SubCateRequest $ request ) { try { $ cateBags = collect ( $ request -> cate_bags ) ; $ defLangCate = $ cateBags -> filter ( function ( $ val , $ key ) { $ defLang = getDefaultLang ( ) ; $ key = 'cate_abbr' ; return $ val [ $ key ] == $ defLang ; } ) ; $ defLangCateDetails = array_values ( $ defLangCate -> all ( ) ) [ 0 ] ; if ( $ request -> has ( 'cate_imag' ) ) { $ imgPath = uploadFile ( 'sub_cates' , $ request -> cate_imag ) ; } else { $ imgPath = '' ; } DB :: beginTransaction ( ) ; $ defLangCateID = SubCate :: insertGetId ( [ 'trans_lang' => strtoupper ( $ defLangCateDetails [ 'cate_abbr' ] ) , 'trans_of' => 0 , 'name' => ucfirst ( $ defLangCateDetails [ 'cate_name' ] ) , 'slug' => $ defLangCateDetails [ 'cate_name' ] , 'photo' => $ imgPath , 'cate_id' => $ request -> input ( 'main_cate' ) , 'status' => $ defLangCateDetails [ 'cate_stat' ] ] ) ; $ restLangsCate = $ cateBags -> filter ( function ( $ val , $ key ) { $ defLang = getDefaultLang ( ) ; $ key = 'cate_abbr' ; return $ val [ $ key ] != $ defLang ; } ) ; if ( isset ( $ restLangsCate ) && $ restLangsCate -> count ( ) > 0 ) { $ restLangsCateData = [ ] ; foreach ( $ restLangsCate as $ restLangCate ) { $ restLangsCateData [ ] = [ 'trans_lang' => strtoupper ( $ restLangCate [ 'cate_abbr' ] ) , 'trans_of' => $ defLangCateID , 'name' => ucfirst ( $ restLangCate [ 'cate_name' ] ) , 'slug' => $ restLangCate [ 'cate_name' ] , 'photo' => $ imgPath , 'cate_id' => $ request -> input ( 'main_cate' ) , 'status' => $ restLangCate [ 'cate_stat' ] ] ; } SubCate :: insert ( $ restLangsCateData ) ; } DB :: commit ( ) ; return redirect ( ) -> route ( 'admin.sub.cates' ) -> with ( [ 'success' => 'Stored Successfully' ] ) ; } catch ( \ Throwable $ th ) { DB :: rollback ( ) ; return redirect ( ) -> route ( 'admin.sub.cates' ) -> with ( [ 'error' => 'Something went terribly wrong' ] ) ; } }
STORE SUB CATEGORY CREATION FORM DATA
STORE SUB CATEGORY CREATION FORM DATA
// CONVERT CATEGORY INPUT BAGS INTO COLLECTION // FILTER THE CATEGORY OF THE DEFAULT LANGUAGE // WEBSITE DEFAULT LANGUAGE // DEFAULT LANGUAGE FILTER KEY // FILTE THE KEY OF A VALUE // CATEGORY OF THE DEFAULT LANGUAGE DETAILS // IMAGE REQUEST EXISTANCE CHECK // UPLOAD IMAGE TO THE SYSTEM FOLDER & GET ITS PATH // MAKE THE PATH EMPTY // START DATABASE TRANSACTIONS // INSERT DATA THE CATEGORY OF DEFAULT LANGUAGE // CATEGORY TRANSLATION LANGUAGE IN UPPER CASE // CATEGORY TRANSLATION OF DEFAUTL LANGUAGE CATEGORY ID // CATEGORY NAME WITH FIRST LETTER IN UPPER CASE // CATEGORY SLUG VALUE // CATEGORY IMAGE PATH // SUB CATEGORY RELATED MAIN CATEGORY // CATEGORY STATUS // FILTER THE CATEGORY OF OTHER LANGUAGES // WEBSITE DEFAULT LANGUAGE // DEFAULT LANGUAGE FILTER KEY // FILTE THE KEY OF A VALUE // REST LANGUAGES CATEGORY EXISTANCE CHECK // REST LANGUAGES CATEGORY EMPTY DATA BOX // REST LANGUAGES CATEGORY LOOP // FILL UP THE REST LANGUAGES CATEGORY BOX WITH DATA // CATEGORY TRANSLATION LANGUAGE IN UPPER CASE // CATEGORY TRANSLATION OF DEFAUTL LANGUAGE CATEGORY ID // CATEGORY NAME WITH FIRST LETTER IN UPPER CASE // CATEGORY SLUG VALUE // CATEGORY IMAGE PATH // SUB CATEGORY RELATED MAIN CATEGORY // CATEGORY STATUS // INSERT THE REST LANGUAGES CATEGORY DATA TO DATABASE // COMMIT DATABASE TRANSACTIONS // REDIRECT TO ADMIN DASHOBOARD WITH SUCCESS MESSAGE // ROLL-BACK THE WHOLE DATABASE TRANSACTIONS // REDIRECT TO ADMIN DASHOBOARD WITH ERROR MESSAGE