I want to store pdf to mongodb using laravel

Hi team,

i’m laravel developer i want to store pdf to mongodb, have done integration connection all i don’t any solution to store pdf. thank you

public function store(Request $request) {                                                            

                     $filename=time().'.'.$request->file->getClientOriginalExtension();

                    $bucket= DB::connection('mongodb')->getMongoDB()->selectGridFSBucket();

                    $stream = $bucket->openUploadStream( $request->file);

                    $metadata = $bucket->getFileDocumentForStream($stream);                                

                    $contents = $filename ;

                    fwrite($stream, $contents);

                    fclose($stream);                                   

                    return Redirect::back()->with('success', '  your case has been created successfully');

        }

why?

Please use some storage service provider to store pdf and store these pdf access links in mongo db. It is better and economical