nesh
nesh

Reputation: 71

How to get path or name of image that store in Storage?

I'm trying to store images in storage also that image name in database.

$file = $request->file('attachments');
Storage::disk('public')->put('images',$file);

$attachments = new Attachment();
$attachments->title = $title;
$attachments->path = "NAME OF IMAGE THAT ALREADY STORED ($FILE)";

$inbox_attachments->save();

Example of image name is

5MgomzwHmMxUhKqRu7T4SMhjvfrWtdKLArBSc3bI.jpg

Upvotes: 1

Views: 319

Answers (1)

Sapnesh Naik
Sapnesh Naik

Reputation: 11636

Use basename:

basename — Returns trailing name component of path

Try this:

$storagePath = Storage::disk('public')->put('images',$file);

$attachments->path = basename($storagePath);

Upvotes: 2

Related Questions