hasFile($field)) { return null; } $file = $request->file($field); $ext = $file->getClientOriginalExtension() ?: ($file->guessExtension() ?: 'jpg'); $path = $file->storeAs('images', Str::random(40) . '.' . $ext, 'public'); return Image::create([ 'user_id' => auth()->id(), 'path' => $path, 'type' => 'public', ])->id; } }