Reza Sam
Reza Sam

Reputation: 1334

UploadedFile in $request

I want to access pic in $request which is instance of UploadedFile class but when I use

$request->pic;

it returns nothing...

this is my dd($request->all()) result

array:4 [
"title" => "blah blah
"desc" => "some text"
"respawn" => "mail"
"pic" => UploadedFile {#27
-test: false
-originalName: "hamayesh-hesabdari2.jpg"
-mimeType: "image/jpeg"
-size: 160295
-error: 0
}
]

how can I access it?

Upvotes: 2

Views: 71

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163748

Use file() method to get the file:

$request->file('pic')

And hasFile() method to check if file exists:

if ($request->hasFile('pic'))

Upvotes: 3

Related Questions