You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorial/markdown/php/quickstart-php-laravel/php-laravel.md
+157-8Lines changed: 157 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -236,27 +236,178 @@ For CRUD operations, we will use the [Key-Value operations](https://docs.couchba
236
236
237
237
### POST Airline
238
238
239
-
Create a new airline document using the POST endpoint.
239
+
Open the `AirlineController.php` file and navigate to the `store` method. The request data is validated and then passed to the model to save the airline document.
240
+
241
+
```php
242
+
// store method in AirlineController.php
243
+
public function store(Request $request, $id)
244
+
{
245
+
if ($errorResponse = $this->validateRequest($request)) {
246
+
return $errorResponse;
247
+
}
248
+
try {
249
+
$data = $request->only($this->allowedAttributes);
250
+
$airline = new Airline($data);
251
+
$airline->saveAirline($id);
252
+
return response()->json(['message' => 'Airline created successfully'], 201);
253
+
} catch (\Exception $e) {
254
+
return response()->json(['message' => 'Internal Server Error'], 500);
255
+
}
256
+
}
257
+
```
258
+
259
+
We call the `saveAirline` method in the Airline model, which uses the [`upsert`](https://docs.couchbase.com/php-sdk/current/howtos/kv-operations.html#upsert) method from the Couchbase SDK. The upsert method inserts a new document or updates an existing one.
Retrieve a specific airline document by its ID using the GET endpoint.
273
+
Navigate to the `show` method in the `AirlineController.php` file. This method retrieves a specific airline document using its ID.
274
+
275
+
```php
276
+
// show method in AirlineController.php
277
+
public function show($id)
278
+
{
279
+
try {
280
+
$airline = Airline::findAirline($id);
281
+
if (!$airline) {
282
+
return response()->json(['message' => 'Airline not found'], 404);
283
+
}
284
+
return response()->json($airline);
285
+
} catch (\Exception $e) {
286
+
return response()->json(['message' => 'Internal Server Error'], 500);
287
+
}
288
+
}
289
+
```
290
+
291
+
We call the `findAirline` method in the Airline model, which uses the [`get`](https://docs.couchbase.com/php-sdk/current/howtos/kv-operations.html#retrieving-documents) method from the Couchbase SDK for key-value retrieval.
Update an existing airline document or create a new one if it doesn't exist using the PUT endpoint.
306
+
The PUT operation uses the same `store` method as POST, leveraging the `upsert` functionality to either update an existing document or create a new one if it doesn't exist.
return response()->json(['message' => 'Internal Server Error'], 500);
332
+
}
333
+
}
334
+
```
335
+
336
+
We call the `destroyAirline` method in the Airline model, which uses the [`remove`](https://docs.couchbase.com/php-sdk/current/howtos/kv-operations.html#removing-documents) method from the Couchbase SDK.
Retrieve a list of airlines with optional filtering by country and pagination using query parameters.
349
+
Navigate to the `index` method in the `AirlineController.php` file. This method retrieves a list of airlines with optional country filtering and pagination.
0 commit comments