1
+ # Laravel Api Response
2
+ Unification of API responses for Laravel projects inspired by telegram api responses.
3
+
1
4
<p align =" center " >
2
5
<img src="https://raw.githubusercontent.com/kolirt/laravel-api-response/v3/cover.png">
3
6
</p >
4
7
5
8
6
- # Laravel Api Response
7
- Unification of API responses for Laravel projects inspired by telegram api responses.
8
-
9
-
10
- # Structure
9
+ ## Structure
11
10
- [ Getting started] ( #getting-started )
12
11
- [ Requirements] ( #requirements )
13
12
- [ Installation] ( #installation )
@@ -34,26 +33,26 @@ Unification of API responses for Laravel projects inspired by telegram api respo
34
33
</a >
35
34
36
35
37
- # Getting started
36
+ ## Getting started
38
37
39
- ## Requirements
38
+ ### Requirements
40
39
- PHP >= 8.1
41
40
- Laravel >= 10
42
41
43
42
For lesser versions of Laravel or PHP, use the [ v2] ( https://github.com/kolirt/laravel-api-response/tree/v2 )
44
43
45
44
46
- ## Installation
45
+ ### Installation
47
46
``` bash
48
47
composer require kolirt/laravel-api-response
49
48
```
50
49
51
50
52
- # Usage
51
+ ## Usage
53
52
54
- ## Example
53
+ ### Example
55
54
56
- ### Error response
55
+ #### Error response
57
56
``` php
58
57
return api()
59
58
->error()
@@ -86,7 +85,7 @@ return api()
86
85
```
87
86
88
87
89
- ### Success response
88
+ #### Success response
90
89
``` php
91
90
return api()
92
91
->success()
@@ -118,40 +117,45 @@ return api()
118
117
```
119
118
120
119
121
- ## Methods
120
+ ### Methods
121
+
122
+ #### ` error `
123
+ Mark response as error
122
124
123
- ### error
124
- Mark response as error.
125
125
``` php
126
126
return api()->error();
127
127
```
128
128
129
129
130
- ### success
131
- Mark response as success.
130
+ #### ` success `
131
+ Mark response as success
132
+
132
133
``` php
133
134
return api()->success();
134
135
```
135
136
136
137
137
- ### setCode
138
- Set specific code to response. Available [ codes] ( https://en.wikipedia.org/wiki/List_of_HTTP_status_codes ) .
138
+ #### ` setCode `
139
+ Set specific code to response. Available [ codes] ( https://en.wikipedia.org/wiki/List_of_HTTP_status_codes )
140
+
139
141
``` php
140
142
return api()->setCode($code);
141
143
```
142
144
143
145
144
- ### setDescription
145
- Add description to response.
146
+ #### ` setDescription `
147
+ Add description to response
148
+
146
149
``` php
147
150
return api()->setDescription(['Description #1', 'Description #2']);
148
151
// or
149
152
return api()->setDescription('Description');
150
153
```
151
154
152
155
153
- ### setErrors
154
- Add errors to response.
156
+ #### ` setErrors `
157
+ Add errors to response
158
+
155
159
``` php
156
160
return api()->setErrors([
157
161
'first_name' => 'Error message',
@@ -160,43 +164,47 @@ return api()->setErrors([
160
164
```
161
165
162
166
163
- ### abort
164
- Abort response with error.
167
+ #### ` abort `
168
+ Abort response with error
169
+
165
170
``` php
166
171
return api()->abort('Error message', 400);
167
172
```
168
173
169
174
170
- ### cookie
171
- Add cookie to response.
175
+ #### ` cookie `
176
+ Add cookie to response
177
+
172
178
``` php
173
179
return api()->cookie(cookie('token', 'asdsadsadas', 60 * 3));
174
180
```
175
181
176
182
177
- ### setData
178
- Add data to response.
183
+ #### ` setData `
184
+ Add data to response
185
+
179
186
``` php
180
187
return api()->setData(['Data #1', 'Data #2']);
181
188
// or
182
189
return api()->setData('Data');
183
190
```
184
191
185
192
186
- ### render
187
- Render response.
193
+ #### ` render `
194
+ Render response
195
+
188
196
``` php
189
197
return api()->render();
190
198
```
191
199
192
200
193
- # FAQ
201
+ ## FAQ
194
202
Check closed [ issues] ( https://github.com/kolirt/laravel-api-response/issues ) to get answers for most asked questions
195
203
196
204
197
- # License
205
+ ## License
198
206
[ MIT] ( LICENSE.txt )
199
207
200
208
201
- # Other packages
209
+ ## Other packages
202
210
Check out my other packages on my [ GitHub profile] ( https://github.com/kolirt )
0 commit comments