Remove SQL column in LARAVEL

  laravel, php

Hello I made this code to delete a column in laravel but the delete () command; Throw me
"Call to a member function delete () on string"

This is the code that results in this string from the sql

    //se elimina correctamente restaurant_user
    $restid = json_encode(DB::table('restaurant_user')->where('restaurant_id', $id)->first());
    //$restid = json_encode($restid);
    //echo "<script>console.log('Con Foreach transactions: " . $restid . "' );</script>";
    if ($restid) {
    $items = $restid;
    //echo "<script>console.log('Tienen que salir todas las variaciones: " . $items . "' );</script>";  
    foreach ((array) $items as $item) {
    echo "<script>console.log('Con Foreach transactions: " . $item . "' );</script>";           
    $item->delete();
    }   
    } else {
    return redirect()->route('admin.restaurants')->with(['message' => 'Algo salio mal en Restaurant_User']);
    }

The $restid varaible throws me this result:

{"id":12,"user_id":4,"restaurant_id":12,"created_at":null,"updated_at":null}

For some reason I can’t delete it

Source: Laravel

Leave a Reply