@@ -27,8 +27,8 @@ public function findAll(): array {
2727 }
2828
2929 /** Find Data by Conditional */
30- public function findBy ($ array ): array {
31- return $ this ->repository ->findBy ($ array );
30+ public function findBy (array $ args ): array {
31+ return $ this ->repository ->findBy ($ args );
3232 }
3333
3434 /** Find Data by Id */
@@ -37,25 +37,30 @@ public function findById($id) {
3737 }
3838
3939 /** Delete Data by Id */
40- public function delete (string $ id ) {
41- $ data = $ this ->repository ->find ($ id );
42- $ this ->entityManager ->remove ($ data );
43- $ this ->entityManager ->flush ();
40+ public function delete (array $ args ) {
41+ $ data = $ this ->repository ->findBy ($ args )[0 ] ?? null ;
4442
45- return $ data ;
43+ if ($ data ):
44+ $ this ->entityManager ->remove ($ data );
45+ $ this ->entityManager ->flush ();
46+
47+ return $ data ;
48+ endif ;
4649 }
4750
4851 /** Update Data by Id */
49- public function update (array $ args , string $ id ) {
50- $ data = $ this ->repository ->find ( $ id ) ;
52+ public function update (array $ data , array $ args ) {
53+ $ item = $ this ->repository ->findBy ( $ args )[ 0 ] ?? null ;
5154
52- foreach ($ args as $ key => $ value )
53- $ data ->__set ($ key , $ value );
55+ if ($ item ):
56+ foreach ($ data as $ key => $ value )
57+ $ item ->__set ($ key , $ value );
5458
55- $ this ->entityManager ->merge ($ data );
56- $ this ->entityManager ->flush ();
59+ $ this ->entityManager ->merge ($ item );
60+ $ this ->entityManager ->flush ();
5761
58- return $ data ;
62+ return $ data ;
63+ endif ;
5964 }
6065
6166 /** Insert Data */
0 commit comments