vendredi 30 avril 2021

Laravel Get Value From json_encode

I can't get value of id from json string.

$photoIdObj = DB::table('images')->select('id')->whereJsonContains('name', ['path' => $photoPath])->get(); 
    $jsonString = json_encode($photoIdObj, true); //object to json string conversion. Result: "[{"id":7}]"
    $jsonArr = json_decode($jsonString); // json string to array
    $photoId = $jsonArr->id;
    
    //$selectedImages = \App\Image::where('id', $jsonString);
    $selectedImages = \App\Image::findOrFail($photoId);
    $selectedImages->forceDelete();

Error message:

"Trying to get property 'id' of non-object"


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire