Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

different name for file in storage and database in Laravel

i have used Storage Facade to store the file in the public storage, after that store the name in the database, but the name of the field are different? so how can store them in the same name in both public storage and database? , I have use this code below:

 if($request->hasFile('file')) {
          $image = $request->file('file');
          $imageName = $image->getClientOriginalName();
          Storage::disk('public')->put('images', $image);

         Post::create([
             'title' => $request->input('title'),
             'content' => $request->input('content'),
             'user_id' => Auth::id(),
             'file' => $imageName,
         ]);

in the storage stored with this name: ejn0Y8flFGGfjllEussig6EO4LB3onEIGoXlOIJV.png
and in the database stored with the original name

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

use putFileAs.so you can pass custom file name as third param.

Storage::disk('public')->putFileAs('images',$image, $imageName);

Ref: Automatic Streaming

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading