Thursday, March 16, 2017

Laravel Eloquent ORM Soft delete and restore many items for me at the same time

i think there is a bug in softdelete and restore with Eloquent ORM in Laravel . i have a table like these My Table Image

and my code to softdelete is

 try {
       $p= Post::findOrFail($id);
    } catch (Exception $e) {
return "error";
    }
    $p->delete();
    return "Post deleted";

and my code for restore is :

`try {
        $p= Post::withTrashed()->findOrFail($id);
    } catch (Exception $e) {
        return "error";
    }
    $p->restore();
    return "Post restored";`

.. the problem is sometimes :
when i delete post number 3 , it delete number 3 and number 2 at the same time and sometimes work fine , n with restore same thing too sometimes i restore for example number 3 n it restore number 1 also at the same time.
i didnt understand why , i tried different code like 'where' statement n 'find' n 'destroy'.
i tried also different version of laravel 5.2 n 5.4 .
i use mysql 5.6.35 , mamp server php 7.1.1.



via Simo

Advertisement