$posterName = $request->file('poster')->getClientOriginalName();
getClientOriginalName Full Code Example
Below are the full code example that you can refer to.
Route::post('/posts/{id}/store-image', function (int $id, Request $request) { $poster = $reqeust->file('poster'); $posterStream = Image::make($poster)->resize(350, 496)->stream('webp', 80); $posterName = '/image/' . $poster->getClientOriginalName() . '.webp'; Storage::disk('public')->put($posterName, $posterStream, 'public'); Post::find($id)->update(['poster_image' => $posterName]); });
Check Uploaded Images
To check if the uploaded image is successful, you can make use of the "hasFile" method.
if ($request->hasFile('poster')) { return $request->file('poster')->getClientOriginalName(); } else { return 'file not exist'; }
Leave a reply