app/Http/Controllers/CategoryController.php
//-- copy img to /img folder and crypt name
copy img to /img folder and crypt name
copy img to / img folder and crypt name
public function product_Add(ProductRequest $request){
        if ($request->hasFile('img')) {
            $image = $request->file('img');
            $name = time().'.'.$image->getClientOriginalExtension();
            $destinationPath = public_path('/img');
            $name = Crypt::encrypt($name);
            $image->move($destinationPath, $name);
        }else{
            $name = null;
        }
        $translation_table = TranslationLang::all();
        foreach ($translation_table as $language){
            $lang = $language->folder;
            $file = $lang.'.json';
            $destinationPath=storage_path('..\resources\lang\\');
            $path_ru = storage_path('..\resources\lang\\'.$file);
            $lang = json_decode(file_get_contents($path_ru), true);
            $lang[$request->product_name] = $request->product_name;
            $lang[$request->product_description] = $request->product_description;
            File::put($destinationPath.$file, json_encode($lang));
        }
        Product::create([
            'parent_id'=>$request->id,
            'img' => $name,
            'name' => $request->product_name,
            'descriptions' => $request->product_description,
            'price' => $request->price,
        ]);
        Category::create([
            'name' => $request->product_name,
            'category_id'=>$request->id,
            'role' => $request->role,
        ]);
        return redirect()->back();
    }
public function product_Add ( ProductRequest $ request ) { if ( $ request -> hasFile ( 'img' ) ) { $ image = $ request -> file ( 'img' ) ; $ name = time ( ) . '.' . $ image -> getClientOriginalExtension ( ) ; $ destinationPath = public_path ( '/img' ) ; $ name = Crypt :: encrypt ( $ name ) ; $ image -> move ( $ destinationPath , $ name ) ; } else { $ name = null ; } $ translation_table = TranslationLang :: all ( ) ; foreach ( $ translation_table as $ language ) { $ lang = $ language -> folder ; $ file = $ lang . '.json' ; $ destinationPath = storage_path ( '..\resources\lang\\' ) ; $ path_ru = storage_path ( '..\resources\lang\\' . $ file ) ; $ lang = json_decode ( file_get_contents ( $ path_ru ) , true ) ; $ lang [ $ request -> product_name ] = $ request -> product_name ; $ lang [ $ request -> product_description ] = $ request -> product_description ; File :: put ( $ destinationPath . $ file , json_encode ( $ lang ) ) ; } Product :: create ( [ 'parent_id' => $ request -> id , 'img' => $ name , 'name' => $ request -> product_name , 'descriptions' => $ request -> product_description , 'price' => $ request -> price , ] ) ; Category :: create ( [ 'name' => $ request -> product_name , 'category_id' => $ request -> id , 'role' => $ request -> role , ] ) ; return redirect ( ) -> back ( ) ; }
copy img to /img folder and crypt name
copy img to / img folder and crypt name