@@ -10,79 +10,80 @@ class ServiceApi implements BaseService
1010 use ResultService;
1111
1212 protected $ title = "" ;
13- protected $ create_message = "" ;
14- protected $ update_message = "" ;
15- protected $ delete_message = "" ;
13+ protected $ create_message = "created successfully " ;
14+ protected $ update_message = "updated successfully " ;
15+ protected $ delete_message = "deleted successfully " ;
16+
1617
1718 /**
18- * Find an item by id
19- * @param mixed $id
20- * @return Model|null
19+ * find by id
20+ * @param $id
21+ * @return \Illuminate\Database\Eloquent\ Model|ServiceApi|ResultService |null
2122 */
2223 public function find ($ id )
2324 {
2425 try {
2526 $ result = $ this ->mainRepository ->find ($ id );
26- return $ this ->setResult ($ result )
27- ->setCode (200 )
28- ->setStatus (true );
27+ return $ this ->setData ($ result )
28+ ->setCode (200 );
2929 } catch (\Exception $ exception ) {
3030 return $ this ->exceptionResponse ($ exception );
3131 }
3232 }
3333
34+
3435 /**
35- * Find an item by id or fail
36- * @param mixed $id
37- * @return Model|null
36+ * find or fail by id
37+ * @param $id
38+ * @return ServiceApi|ResultService|mixed
3839 */
3940 public function findOrFail ($ id )
4041 {
4142 try {
4243 $ result = $ this ->mainRepository ->findOrFail ($ id );
43- return $ this ->setResult ($ result )
44- ->setCode (200 )
45- ->setStatus (true );
44+ return $ this ->setData ($ result )
45+ ->setCode (200 );
4646 } catch (\Exception $ exception ) {
4747 return $ this ->exceptionResponse ($ exception );
4848 }
4949 }
5050
51+
5152 /**
52- * Return all items
53- * @return Collection|null
53+ * all data
54+ * @return \Illuminate\Database\Eloquent\ Collection|ServiceApi|ResultService |null
5455 */
5556 public function all ()
5657 {
5758 try {
5859 $ result = $ this ->mainRepository ->all ();;
59- return $ this ->setResult ($ result )
60- ->setCode (200 )
61- ->setStatus (true );
60+ return $ this ->setData ($ result )
61+ ->setCode (200 );
6262 } catch (\Exception $ exception ) {
6363 return $ this ->exceptionResponse ($ exception );
6464 }
6565 }
6666
67+
6768 /**
68- * Create an item
69- * @param array|mixed $data
70- * @return Model|null
69+ * create data
70+ * @param $data
71+ * @return \Illuminate\Database\Eloquent\ Model|ServiceApi|ResultService |null
7172 */
7273 public function create ($ data )
7374 {
7475 try {
75- $ this ->mainRepository ->create ($ data );
76+ $ data = $ this ->mainRepository ->create ($ data );
7677 return $ this ->setMessage ($ this ->title ." " .$ this ->create_message )
7778 ->setCode (200 )
78- ->setStatus ( true );
79+ ->setData ( $ data );
7980 } catch (\Exception $ exception ) {
8081 return $ this ->exceptionResponse ($ exception );
8182 }
8283 }
8384
8485 /**
85- * Update a model
86+ * Update data
8687 * @param int|mixed $id
8788 * @param array|mixed $data
8889 * @return bool|mixed
@@ -92,24 +93,22 @@ public function update($id, array $data)
9293 try {
9394 $ this ->mainRepository ->update ($ id , $ data );
9495 return $ this ->setMessage ($ this ->title ." " .$ this ->update_message )
95- ->setCode (200 )
96- ->setStatus (true );
96+ ->setCode (200 );
9797 } catch (\Exception $ exception ) {
9898 return $ this ->exceptionResponse ($ exception );
9999 }
100100 }
101101
102102 /**
103- * Delete a model
103+ * Delete data by id
104104 * @param int|Model $id
105105 */
106106 public function delete ($ id )
107107 {
108108 try {
109109 $ this ->mainRepository ->delete ($ id );
110110 return $ this ->setMessage ($ this ->title ." " .$ this ->delete_message )
111- ->setCode (200 )
112- ->setStatus (true );
111+ ->setCode (200 );
113112 } catch (\Exception $ exception ) {
114113 return $ this ->exceptionResponse ($ exception );
115114 }
@@ -125,8 +124,7 @@ public function destroy(array $id)
125124 try {
126125 $ this ->mainRepository ->destroy ($ id );
127126 return $ this ->setMessage ($ this ->title ." " .$ this ->delete_message )
128- ->setCode (200 )
129- ->setStatus (true );
127+ ->setCode (200 );
130128 } catch (\Exception $ exception ) {
131129 return $ this ->exceptionResponse ($ exception );
132130 }
0 commit comments