src/Models/Database/Product.php
protected function saveProductDownloadable($data)
    {
        if (isset($data['downloadable']) && count($data['downloadable']) > 0) {
            $repository = App::get(ProductDownloadableUrlInterface::class);

            $mainDownloadableMedia = ($data['downloadable']['main_product']) ?? null;

            if (null === $mainDownloadableMedia) {
                throw new \Exception('Invalid Downloadable Media Given or Nothing Given');
            }

            $tmpPath = str_split(strtolower(str_random(3)));
            $path = 'uploads/downloadables/' . implode('/', $tmpPath);
            $dbPath = $mainDownloadableMedia->store($path, 'avored');
            $token = str_random(32);

            $downModel = $repository->query()->whereProductId($this->id)->first();

            if (null === $downModel) {
                $downModel = ProductDownloadableUrl::create([
                    'token' => $token,
                    'product_id' => $this->id,
                    'main_path' => $dbPath
                ]);
            } else {
                $downModel->update(['main_path' => $dbPath]);
            }

            $demoDownloadableMedia = ($data['downloadable']['demo_product']) ?? null;

            if (null !== $demoDownloadableMedia) {
                $tmpPath = str_split(strtolower(str_random(3)));
                $path = 'uploads/downloadables/' . implode('/', $tmpPath);
                $demoDbPath = $demoDownloadableMedia->store($path, 'avored');

                $downModel->update(['demo_path' => $demoDbPath]);
            }
        }
    }
protected function saveProductDownloadable($data)
    {
        if (isset($data['downloadable']) && count($data['downloadable']) > 0) {
            $repository = App::get(ProductDownloadableUrlInterface::class);

            $mainDownloadableMedia = ($data['downloadable']['main_product']) ?? null;

            if (null === $mainDownloadableMedia) {
                throw new \Exception('Invalid Downloadable Media Given or Nothing Given');
            }

            $tmpPath = str_split(strtolower(str_random(3)));
            $path = 'uploads/downloadables/' . implode('/', $tmpPath);
            $dbPath = $mainDownloadableMedia->store($path, 'avored');
            $token = str_random(32);

            $downModel = $repository->query()->whereProductId($this->id)->first();

            if (null === $downModel) {
                $downModel = ProductDownloadableUrl::create([
                    'token' => $token,
                    'product_id' => $this->id,
                    'main_path' => $dbPath
                ]);
            } else {
                $downModel->update(['main_path' => $dbPath]);
            }

            $demoDownloadableMedia = ($data['downloadable']['demo_product']) ?? null;

            if (null !== $demoDownloadableMedia) {
                $tmpPath = str_split(strtolower(str_random(3)));
                $path = 'uploads/downloadables/' . implode('/', $tmpPath);
                $demoDbPath = $demoDownloadableMedia->store($path, 'avored');

                $downModel->update(['demo_path' => $demoDbPath]);
            }
        }
    }
protected function saveProductDownloadable ( $ data ) { if ( isset ( $ data [ 'downloadable' ] ) && count ( $ data [ 'downloadable' ] ) > 0 ) { $ repository = App :: get ( ProductDownloadableUrlInterface :: class ) ; $ mainDownloadableMedia = ( $ data [ 'downloadable' ] [ 'main_product' ] ) ?? null ; if ( null === $ mainDownloadableMedia ) { throw new \ Exception ( 'Invalid Downloadable Media Given or Nothing Given' ) ; } $ tmpPath = str_split ( strtolower ( str_random ( 3 ) ) ) ; $ path = 'uploads/downloadables/' . implode ( '/' , $ tmpPath ) ; $ dbPath = $ mainDownloadableMedia -> store ( $ path , 'avored' ) ; $ token = str_random ( 32 ) ; $ downModel = $ repository -> query ( ) -> whereProductId ( $ this -> id ) -> first ( ) ; if ( null === $ downModel ) { $ downModel = ProductDownloadableUrl :: create ( [ 'token' => $ token , 'product_id' => $ this -> id , 'main_path' => $ dbPath ] ) ; } else { $ downModel -> update ( [ 'main_path' => $ dbPath ] ) ; } $ demoDownloadableMedia = ( $ data [ 'downloadable' ] [ 'demo_product' ] ) ?? null ; if ( null !== $ demoDownloadableMedia ) { $ tmpPath = str_split ( strtolower ( str_random ( 3 ) ) ) ; $ path = 'uploads/downloadables/' . implode ( '/' , $ tmpPath ) ; $ demoDbPath = $ demoDownloadableMedia -> store ( $ path , 'avored' ) ; $ downModel -> update ( [ 'demo_path' => $ demoDbPath ] ) ; } } }
Save Product Downloadable Information

@param array $data
@return void
Save Product Downloadable Information