0

Any Idea how to edit pictures on Cloudinary using Laravel API? I did a lot of searches, but I didn't find any references. The add worked successfully, but I didn't find a solution for the edit.

Add code

$user->user_image = Cloudinary::upload(
    $request->file('user_image')->getRealPath(),
    [
        'folder' => 'Testing'
    ]
)->getSecurePath();

Attempt at updating picture

public function updatePicture(Request $request, $user_id)
{
    $data = $request->validate([
        'user_image' => '',
    ]);

    $data = Cloudinary::upload(
        $request->file('user_image')->getRealPath(),
        [
            'folder' => 'Testing'
        ]
    )->getSecurePath();
    
    User::where("user_id", $user_id)->update($data);

    return response()->json([
        'message' => 'Successfully updated Picture!',
        'success' => true,
    ], 200);
}
stack user
  • 37
  • 3

1 Answers1

0

For deleting, you can use the destroy() method of the API, for example:

$result = Cloudinary::destroy(
        $public_id, //Public ID of the file from Cloudianry to delete - returned from the Upload API response
        [
            '...' => '...' //any optional parameters
        ]
    )

For a list of all optional parameters and possible values please see: https://cloudinary.com/documentation/image_upload_api_reference#destroy_method

In terms of updating, I am assuming you are referring to Cloudinary's update details of a single resource method of the Admin API. If so, you can access it like so:

$admin_api = Cloudinary::admin();
$result = $admin_api->update($public_id, $options = []);

Alternatively, if you're referring to the explicit method of the Upload API then you could access it like so:

$result = Cloudinary::explicit($public_id, $options = []);
Aleksandar
  • 1,385
  • 6
  • 13