{"id":10190,"date":"2025-12-17T23:47:16","date_gmt":"2025-12-18T07:47:16","guid":{"rendered":"https:\/\/www.couchbase.com\/developers\/tutorials\/quickstart-php-laravel\/"},"modified":"2025-12-17T23:47:16","modified_gmt":"2025-12-18T07:47:16","slug":"quickstart-php-laravel","status":"publish","type":"tutorials","link":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/quickstart-php-laravel\/","title":{"rendered":"Quickstart in Couchbase with PHP and Laravel"},"content":{"rendered":"\n<h3 id=\"h-getting-started\" class=\"wp-block-heading\">Getting Started<\/h3>\n\n\n\n<h4 id=\"h-prerequisites\" class=\"wp-block-heading\">Prerequisites<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To run this prebuilt project, you will need:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.couchbase.com\/products\/capella\/\">Couchbase Capella<\/a> cluster with <a href=\"https:\/\/docs.couchbase.com\/php-sdk\/current\/ref\/travel-app-data-model.html\">travel-sample<\/a> bucket loaded.\n<ul>\n<li>To run this tutorial using a self managed Couchbase cluster, please refer to the <a href=\"#running-self-managed-couchbase-cluster\">appendix<\/a>.<\/li>\n<\/ul>\n<\/li>\n\n\n<li><a href=\"https:\/\/www.php.net\/downloads.php\">PHP<\/a> 8.2 or higher installed\n<ul>\n<li>Ensure that the PHP version is <a href=\"https:\/\/docs.couchbase.com\/php-sdk\/current\/project-docs\/compatibility.html#php-version-compat\">compatible<\/a> with the Couchbase SDK.<\/li>\n<\/ul>\n<\/li>\n\n\n<li>Code Editor installed (Visual Studio Code, PhpStorm, or Sublime Text)<\/li>\n\n\n<li>Composer command line<\/li>\n\n<\/ul>\n\n\n\n<h4 id=\"h-source-code\" class=\"wp-block-heading\">Source Code<\/h4>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code>git clone https:\/\/github.com\/couchbase-examples\/php-laravel-quickstart.git\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-change-directory\" class=\"wp-block-heading\">Change Directory<\/h4>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code>cd php-laravel-quickstart\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-install-dependencies\" class=\"wp-block-heading\">Install Dependencies<\/h4>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code>cd php-laravel-quickstart\ncomposer install\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Note: Composer automatically installs the required dependencies when building the project.<\/p>\n<\/blockquote>\n\n\n\n<h4 id=\"h-initial-configuration\" class=\"wp-block-heading\">Initial Configuration<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After installing dependencies, you need to set up the basic Laravel configuration:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create the environment file:<\/li>\n\n<\/ol>\n\n\n\n<pre class=\"wp-block-code language-sh\"><code>cp .env.example .env\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Generate application key:<\/li>\n\n<\/ol>\n\n\n\n<pre class=\"wp-block-code language-sh\"><code>php artisan key:generate\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-couchbase-service-provider\" class=\"wp-block-heading\">Couchbase Service Provider<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>CouchbaseServiceProvider<\/code> class is a Laravel service provider class responsible for setting up the connection to a Couchbase database in a Laravel application.<\/p>\n\n\n\n<h4 id=\"h-application-environment\" class=\"wp-block-heading\">Application Environment<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">All configuration for communication with the database is read from environment variables. As a security best practice, you should set these values in your <code>.env<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-code language-env\"><code>DB_CONN_STR=&lt;connection_string&gt;\nDB_USERNAME=&lt;username&gt;\nDB_PASSWORD=&lt;password&gt;\nDB_BUCKET=travel-sample\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace the placeholder values with your actual Couchbase cluster details.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The connection string should be in the following format:<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>return [\n    &#039;host&#039; =&gt; env(&#039;DB_CONN_STR&#039;, &#039;couchbase:\/\/127.0.0.1&#039;),\n    &#039;username&#039; =&gt; env(&#039;DB_USERNAME&#039;, &#039;Administrator&#039;),\n    &#039;password&#039; =&gt; env(&#039;DB_PASSWORD&#039;, &#039;password&#039;),\n    &#039;bucket&#039; =&gt; env(&#039;DB_BUCKET&#039;, &#039;travel-sample&#039;),\n];\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For more information on the Laravel connection string, see the <a href=\"https:\/\/laravel.com\/docs\/8.x\/database#configuration\">Database Configuration<\/a> documentation.<\/p>\n\n\n\n<h3 id=\"h-running-the-application\" class=\"wp-block-heading\">Running The Application<\/h3>\n\n\n\n<h4 id=\"h-directly-on-the-machine\" class=\"wp-block-heading\">Directly on the machine<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">At this point the application is ready, and you can run it via the command line:<\/p>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code>php artisan serve\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Note: Either the Couchbase Server must be installed and running on localhost or the connection string must be updated in the <code>config\/couchbase.php<\/code> file.<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Tip: If Swagger UI loads without endpoints, generate the docs:<\/p>\n\n\n\n<pre class=\"wp-block-code language-sh\"><code>php artisan l5-swagger:generate\n<\/code><\/pre>\n<\/blockquote>\n\n\n\n<h4 id=\"h-docker\" class=\"wp-block-heading\">Docker<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Build the Docker image<\/p>\n\n\n\n<pre class=\"wp-block-code language-sh\"><code>docker build -t php-laravel-quickstart .\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run the Docker image<\/p>\n\n\n\n<pre class=\"wp-block-code language-sh\"><code>docker run -d --name laravel-container -p 8000:8000 \n  -e DB_CONN_STR=&lt;connection_string&gt; \n  -e DB_USERNAME=&lt;username&gt; \n  -e DB_PASSWORD=&lt;password&gt; \n  -e DB_BUCKET=travel-sample \n  php-laravel-quickstart\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Note: Environment variables passed to the Docker container will override the default values in the configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once the application is running, you can access it in your browser at <a href=\"http:\/\/localhost:8000\">http:\/\/localhost:8000<\/a>. Swagger UI is available at <a href=\"http:\/\/localhost:8000\/api\/documentation\">http:\/\/localhost:8000\/api\/documentation<\/a>.<\/p>\n\n\n\n<h4 id=\"h-verifying-the-application\" class=\"wp-block-heading\">Verifying the Application<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Once the application starts, you can see the details of the application on the logs.\n<img decoding=\"async\" src=\".\/php-quickstart-app-startup.png\" alt=\"Application Startup\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The application will run on port 8000 of your local machine (<a href=\"http:\/\/localhost:8000\">http:\/\/localhost:8000<\/a>). Open Swagger UI at <a href=\"http:\/\/localhost:8000\/api\/documentation\">http:\/\/localhost:8000\/api\/documentation<\/a> to try the API endpoints. Swagger documentation is used in this demo to showcase the different API endpoints and how they can be invoked. More details on the Swagger documentation can be found in the <a href=\"#swagger-documentation\">appendix<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/php-quickstart-swagger.png\" alt=\"Swagger Documentation\"><\/p>\n\n\n\n<h3 id=\"h-data-model\" class=\"wp-block-heading\">Data Model<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For this tutorial, we use three collections, <code>airport<\/code>, <code>airline<\/code> and <code>route<\/code> that contain sample airports, airlines and airline routes respectively. The route collection connects the airports and airlines as seen in the figure below. We use these connections in the quickstart to generate airports that are directly connected and airlines connecting to a destination airport. Note that these are just examples to highlight how you can use SQL queries to join the collections.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/travel_sample_data_model.png\" alt=\"Data Model\"><\/p>\n\n\n\n<h3 id=\"h-airline-document-structure\" class=\"wp-block-heading\">Airline Document Structure<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We will be setting up a REST API to manage some airline documents. The <code>name<\/code> field is the name of the airline. The <code>callsign<\/code> field is the callsign of the airline. The <code>iata<\/code> field is the IATA code of the airline. The <code>icao<\/code> field is the ICAO code of the airline. The <code>country<\/code> field is the country of the airline.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our airline document will have a structure similar to the following example:<\/p>\n\n\n\n<pre class=\"wp-block-code language-json\"><code>{\n    &quot;name&quot;: &quot;Couchbase Airways&quot;,\n    &quot;callsign&quot;: &quot;Couchbase&quot;,\n    &quot;iata&quot;: &quot;CB&quot;,\n    &quot;icao&quot;: &quot;CBA&quot;,\n    &quot;country&quot;: &quot;United States&quot;\n}\n<\/code><\/pre>\n\n\n\n<h3 id=\"h-code-structure\" class=\"wp-block-heading\">Code Structure<\/h3>\n\n\n\n<h4 id=\"h-project-structure\" class=\"wp-block-heading\">Project Structure<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>.\n\u251c\u2500\u2500 app\/\n\u2502   \u251c\u2500\u2500 Http\/\n\u2502   \u2502   \u2514\u2500\u2500 Controllers\/\n\u2502   \u2502       \u251c\u2500\u2500 AirlineController.php\n\u2502   \u2502       \u251c\u2500\u2500 AirportController.php\n\u2502   \u2502       \u251c\u2500\u2500 RouteController.php\n\u2502   \u2502       \u2514\u2500\u2500 HotelController.php\n\u2502   \u251c\u2500\u2500 Models\/\n\u2502   \u2502   \u251c\u2500\u2500 Airline.php\n\u2502   \u2502   \u251c\u2500\u2500 Airport.php\n\u2502   \u2502   \u251c\u2500\u2500 Route.php\n\u2502   \u2502   \u2514\u2500\u2500 Hotel.php\n\u2502   \u2514\u2500\u2500 Providers\/\n\u2502       \u2514\u2500\u2500 CouchbaseServiceProvider.php\n\u251c\u2500\u2500 config\/\n\u2502   \u2514\u2500\u2500 couchbase.php\n\u251c\u2500\u2500 routes\/\n\u2502   \u2514\u2500\u2500 api.php\n\u2514\u2500\u2500 tests\/\n    \u2514\u2500\u2500 Feature\/\n        \u251c\u2500\u2500 AirlineTest.php\n        \u251c\u2500\u2500 AirportTest.php\n        \u251c\u2500\u2500 RouteTest.php\n        \u2514\u2500\u2500 HotelTest.php\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-key-components\" class=\"wp-block-heading\">Key Components<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Controllers<\/strong>: Handle HTTP requests and responses for each entity<\/li>\n\n\n<li><strong>Models<\/strong>: Define data structures and business logic for Couchbase operations<\/li>\n\n\n<li><strong>Service Provider<\/strong>: Configures Couchbase connection and collection references<\/li>\n\n\n<li><strong>Tests<\/strong>: Integration tests for all API endpoints<\/li>\n\n<\/ul>\n\n\n\n<h4 id=\"h-airline-entity\" class=\"wp-block-heading\">Airline Entity<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">For this tutorial, we will focus on the airline entity to demonstrate CRUD operations and SQL++ queries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will be setting up a REST API to manage airline documents:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#post-airline\">POST Airline<\/a> \u2013 Create a new airline<\/li>\n\n\n<li><a href=\"#get-airline\">GET Airline<\/a> \u2013 Read specified airline<\/li>\n\n\n<li><a href=\"#put-airline\">PUT Airline<\/a> \u2013 Update specified airline<\/li>\n\n\n<li><a href=\"#delete-airline\">DELETE Airline<\/a> \u2013 Delete airline<\/li>\n\n\n<li><a href=\"#list-airlines\">List Airlines<\/a> \u2013 Get all airlines. Optionally filter the list by country<\/li>\n\n\n<li><a href=\"#airlines-to-destination\">Airlines to Destination<\/a> \u2013 Get airlines flying to a destination airport<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For CRUD operations, we will use the <a href=\"https:\/\/docs.couchbase.com\/php-sdk\/current\/howtos\/kv-operations.html\">Key-Value operations<\/a> that are built into the Couchbase SDK to create, read, update, and delete a document. Every document will need an ID (similar to a primary key in other databases) to save it to the database. This ID is passed in the URL. For other endpoints, we will use <a href=\"https:\/\/docs.couchbase.com\/php-sdk\/current\/howtos\/n1ql-queries-with-sdk.html\">SQL++<\/a> to query for documents.<\/p>\n\n\n\n<h4 id=\"h-post-airline\" class=\"wp-block-heading\">POST Airline<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Open the <code>AirlineController.php<\/code> file and navigate to the <code>store<\/code> method. The request data is validated and then passed to the model to save the airline document.<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>\/\/ store method in AirlineController.php\npublic function store(Request $request, $id)\n{\n    if ($errorResponse = $this-&gt;validateRequest($request)) {\n        return $errorResponse;\n    }\n    try {\n        $data = $request-&gt;only($this-&gt;allowedAttributes);\n        $airline = new Airline($data);\n        $airline-&gt;saveAirline($id);\n        return response()-&gt;json([&#039;message&#039; =&gt; &#039;Airline created successfully&#039;], 201);\n    } catch (Exception $e) {\n        return response()-&gt;json([&#039;message&#039; =&gt; &#039;Internal Server Error&#039;], 500);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We call the <code>saveAirline<\/code> method in the Airline model, which uses the <a href=\"https:\/\/docs.couchbase.com\/php-sdk\/current\/howtos\/kv-operations.html#upsert\"><code>upsert<\/code><\/a> method from the Couchbase SDK. The upsert method inserts a new document or updates an existing one.<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>\/\/ saveAirline method in Airline model\npublic function saveAirline($id)\n{\n    $data = $this-&gt;attributesToArray();\n    unset($data[&#039;id&#039;]);\n    $this-&gt;bucket-&gt;scope(&#039;inventory&#039;)-&gt;collection(&#039;airline&#039;)-&gt;upsert($id, $data);\n}\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-get-airline\" class=\"wp-block-heading\">GET Airline<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to the <code>show<\/code> method in the <code>AirlineController.php<\/code> file. This method retrieves a specific airline document using its ID.<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>\/\/ show method in AirlineController.php\npublic function show($id)\n{\n    try {\n        $airline = Airline::findAirline($id);\n        if (!$airline) {\n            return response()-&gt;json([&#039;message&#039; =&gt; &#039;Airline not found&#039;], 404);\n        }\n        return response()-&gt;json($airline);\n    } catch (Exception $e) {\n        return response()-&gt;json([&#039;message&#039; =&gt; &#039;Internal Server Error&#039;], 500);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We call the <code>findAirline<\/code> method in the Airline model, which uses the <a href=\"https:\/\/docs.couchbase.com\/php-sdk\/current\/howtos\/kv-operations.html#retrieving-documents\"><code>get<\/code><\/a> method from the Couchbase SDK for key-value retrieval.<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>\/\/ findAirline method in Airline model\npublic static function findAirline($id)\n{\n    $instance = new static;\n    $document = $instance-&gt;bucket-&gt;scope(&#039;inventory&#039;)-&gt;collection(&#039;airline&#039;)-&gt;get($id);\n    $data = $document-&gt;content();\n    return new static($data);\n}\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-put-airline\" class=\"wp-block-heading\">PUT Airline<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The PUT operation uses the same <code>store<\/code> method as POST, leveraging the <code>upsert<\/code> functionality to either update an existing document or create a new one if it doesn&#8217;t exist.<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>\/\/ Same store method handles both POST and PUT\n$airline-&gt;saveAirline($id); \/\/ Uses upsert internally\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>upsert<\/code> operation in Couchbase automatically handles both insert and update scenarios, making it perfect for PUT requests.<\/p>\n\n\n\n<h4 id=\"h-delete-airline\" class=\"wp-block-heading\">DELETE Airline<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to the <code>destroy<\/code> method in the <code>AirlineController.php<\/code> file. This method deletes an airline document by its ID.<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>\/\/ destroy method in AirlineController.php\npublic function destroy($id)\n{\n    try {\n        $airline = Airline::findAirline($id);\n        if (!$airline) {\n            return response()-&gt;json([&#039;message&#039; =&gt; &#039;Airline not found&#039;], 404);\n        }\n        Airline::destroyAirline($id);\n        return response()-&gt;json([&#039;message&#039; =&gt; &#039;Airline deleted successfully&#039;], 200);\n    } catch (Exception $e) {\n        return response()-&gt;json([&#039;message&#039; =&gt; &#039;Internal Server Error&#039;], 500);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We call the <code>destroyAirline<\/code> method in the Airline model, which uses the <a href=\"https:\/\/docs.couchbase.com\/php-sdk\/current\/howtos\/kv-operations.html#removing-documents\"><code>remove<\/code><\/a> method from the Couchbase SDK.<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>\/\/ destroyAirline method in Airline model\npublic static function destroyAirline($id)\n{\n    $instance = new static;\n    $instance-&gt;bucket-&gt;scope(&#039;inventory&#039;)-&gt;collection(&#039;airline&#039;)-&gt;remove($id);\n}\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-list-airlines\" class=\"wp-block-heading\">List Airlines<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to the <code>index<\/code> method in the <code>AirlineController.php<\/code> file. This method retrieves a list of airlines with optional country filtering and pagination.<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>\/\/ index method in AirlineController.php\npublic function index(Request $request)\n{\n    try {\n        $offset = $request-&gt;query(&#039;offset&#039;, 0);\n        $limit = $request-&gt;query(&#039;limit&#039;, 10);\n        $country = $request-&gt;query(&#039;country&#039;);\n        $airlines = Airline::getAllAirlinesByCountry($country, $offset, $limit);\n        return response()-&gt;json($airlines);\n    } catch (Exception $e) {\n        return response()-&gt;json([&#039;message&#039; =&gt; &#039;Internal Server Error&#039;], 500);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We call the <code>getAllAirlinesByCountry<\/code> method in the Airline model, which uses SQL++ queries to retrieve filtered results.<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>\/\/ getAllAirlinesByCountry method in Airline model\npublic static function getAllAirlinesByCountry($country, $offset = 0, $limit = 10)\n{\n    $query = &quot;SELECT * FROM `travel-sample`.`inventory`.`airline`&quot;;\n    if ($country) {\n        $query .= &quot; WHERE country = &#039;$country&#039;&quot;;\n    }\n    $query .= &quot; LIMIT $limit OFFSET $offset&quot;;\n    \n    $result = $instance-&gt;bucket-&gt;scope(&#039;inventory&#039;)-&gt;query($query);\n    return collect($result-&gt;rows());\n}\n<\/code><\/pre>\n\n\n\n<h4 id=\"h-airlines-to-destination\" class=\"wp-block-heading\">Airlines to Destination<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This endpoint demonstrates SQL++ queries with JOINs to find airlines that fly to a specific destination airport.<\/p>\n\n\n\n<pre class=\"wp-block-code language-php\"><code>\/\/ getAirlinesToAirport method in Airline model\npublic static function getAirlinesToAirport($destinationAirportCode, $offset = 0, $limit = 10)\n{\n    $query = &quot;\n    SELECT air.callsign, air.country, air.iata, air.icao, META(air).id AS id, air.name\n    FROM (\n        SELECT DISTINCT route.airlineid AS airlineId\n        FROM `travel-sample`.`inventory`.`route` AS route\n        WHERE route.destinationairport = &#039;$destinationAirportCode&#039;\n    ) AS subquery\n    JOIN `travel-sample`.`inventory`.`airline` AS air ON META(air).id = subquery.airlineId\n    LIMIT $limit OFFSET $offset&quot;;\n    \n    $result = $instance-&gt;bucket-&gt;scope(&#039;inventory&#039;)-&gt;query($query);\n    return collect($result-&gt;rows());\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This query demonstrates advanced SQL++ features:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Subquery<\/strong>: Finds distinct airline IDs from routes to the destination<\/li>\n\n\n<li><strong>JOIN<\/strong>: Connects route and airline collections<\/li>\n\n\n<li><strong>META()<\/strong>: Accesses document metadata to get the document ID<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-running-the-tests\" class=\"wp-block-heading\">Running The Tests<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This command will execute all the test cases in your project.<\/p>\n\n\n\n<pre class=\"wp-block-code language-sh\"><code>php artisan test\n<\/code><\/pre>\n\n\n\n<h3 id=\"h-project-setup-notes\" class=\"wp-block-heading\">Project Setup Notes<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This project was based on the standard <a href=\"https:\/\/laravel.com\/docs\">Laravel project<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A full list of packages are referenced in the <code>composer.json<\/code> file.<\/p>\n\n\n\n<h3 id=\"h-contributing\" class=\"wp-block-heading\">Contributing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Contributions are welcome! If you&#8217;d like to contribute to this project, please fork the repository and create a pull request.<\/p>\n\n\n\n<h3 id=\"h-appendix\" class=\"wp-block-heading\">Appendix<\/h3>\n\n\n\n<h4 id=\"h-extending-api-by-adding-new-entity\" class=\"wp-block-heading\">Extending API by Adding New Entity<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">If you would like to add another entity to the APIs, follow these steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p><strong>Create the new entity (collection) in the Couchbase bucket:<\/strong> You can create the collection using the <a href=\"https:\/\/docs.couchbase.com\/php-sdk\/current\/howtos\/provisioning-cluster-resources.html#collection-management\">SDK<\/a> or via the <a href=\"https:\/\/docs.couchbase.com\/cloud\/n1ql\/n1ql-language-reference\/createcollection.html\">Couchbase Server interface<\/a>.<\/p>\n<\/li>\n\n\n<li>\n<p><strong>Define the model:<\/strong> Create a new model in the <code>app\/Models<\/code> directory, similar to the existing <code>Airline<\/code> model. Note that this quickstart already includes a <code>Hotel<\/code> model as an example. For a new entity, you would create a similar structure:<\/p>\n<pre><code class=\"language-php\">namespace AppModels;\n\nuse IlluminateDatabaseEloquentModel;\n\nclass YourEntity extends Model\n{\n    protected $bucket;\n\n    protected $fillable = [\n        \/\/ Define your entity fields here\n    ];\n\n    public function __construct(array $attributes = [])\n    {\n        parent::__construct($attributes);\n        $this-&gt;bucket = app('couchbase.bucket');\n    }\n\n    \/\/ Add methods for querying, saving, and deleting data\n}\n<\/code><\/pre>\n<\/li>\n\n\n<li>\n<p><strong>Define the controller:<\/strong> Create a new controller in the <code>app\/Http\/Controllers<\/code> directory, similar to the existing <code>AirlineController<\/code>. For example, you can create a file <code>HotelController.php<\/code>:<\/p>\n<pre><code class=\"language-php\">namespace AppHttpControllers;\n\nuse IlluminateHttpRequest;\nuse AppModelsHotel;\n\nclass HotelController extends Controller\n{\n    \/\/ Add methods for handling HTTP requests for the Hotel entity\n}\n<\/code><\/pre>\n<\/li>\n\n\n<li>\n<p><strong>Define the routes:<\/strong> In the <code>routes\/api.php<\/code> file, define the routes for the new entity similar to the existing routes for airlines:<\/p>\n<pre><code class=\"language-php\">Route::prefix('v1\/hotels')-&gt;group(function () {\n    Route::get('list', 'HotelController@index');\n    Route::get('{id}', 'HotelController@show');\n    Route::post('{id}', 'HotelController@store');\n    Route::put('{id}', 'HotelController@update');\n    Route::delete('{id}', 'HotelController@destroy');\n});\n<\/code><\/pre>\n<\/li>\n\n\n<li>\n<p><strong>Integration tests:<\/strong> Create a new test class in the <code>tests\/Feature<\/code> directory, similar to the existing tests. For example, you can create a file <code>HotelIntegrationTest.php<\/code>:<\/p>\n<pre><code class=\"language-php\">namespace TestsFeature;\n\nuse TestsTestCase;\n\nclass HotelIntegrationTest extends TestCase\n{\n    \/\/ Add test methods for the Hotel endpoints\n}\n<\/code><\/pre>\n<\/li>\n\n<\/ul>\n\n\n\n<h4 id=\"h-running-self-managed-couchbase-cluster\" class=\"wp-block-heading\">Running Self Managed Couchbase Cluster<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">If you are running this quickstart with a self-managed Couchbase cluster, you need to <a href=\"https:\/\/docs.couchbase.com\/server\/current\/manage\/manage-settings\/install-sample-buckets.html\">load<\/a> the travel-sample data bucket in your cluster and generate the credentials for the bucket.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You need to update the connection string and the credentials in the <code>config\/couchbase.php<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-code language-env\"><code>DB_CONN_STR=couchbase:\/\/&lt;your-couchbase-server&gt;\nDB_USERNAME=&lt;your-username&gt;\nDB_PASSWORD=&lt;your-password&gt;\nDB_BUCKET=travel-sample\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>&lt;your-couchbase-server&gt;<\/code>, <code>&lt;your-username&gt;<\/code>, and <code>&lt;your-password&gt;<\/code> with your actual Couchbase server details and credentials.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>NOTE:<\/strong> Couchbase must be installed and running prior to running the Laravel app.<\/p>\n<\/blockquote>\n\n\n\n<h4 id=\"h-swagger-documentation\" class=\"wp-block-heading\">Swagger Documentation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Swagger documentation provides a clear view of the API including endpoints, HTTP methods, request parameters, and response objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Click on an individual endpoint to expand it and see detailed information. This includes the endpoint&#8217;s description, possible response status codes, and the request parameters it accepts.<\/p>\n\n\n\n<h5 id=\"h-trying-out-the-api\" class=\"wp-block-heading\">Trying Out the API<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">You can try out an API by clicking on the &#8220;Try it out&#8221; button next to the endpoints.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\n<p>Parameters: If an endpoint requires parameters, Swagger UI provides input boxes for you to fill in. This could include path parameters, query strings, headers, or the body of a POST\/PUT request.<\/p>\n<\/li>\n\n\n<li>\n<p>Execution: Once you&#8217;ve inputted all the necessary parameters, you can click the &#8220;Execute&#8221; button to make a live API call. Swagger UI will send the request to the API and display the response directly in the documentation. This includes the response code, response headers, and response body.<\/p>\n<\/li>\n\n<\/ul>\n\n\n\n<h5 id=\"h-models\" class=\"wp-block-heading\">Models<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Swagger documents the structure of request and response bodies using models. These models define the expected data structure using JSON schema and are extremely helpful in understanding what data to send and expect.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Getting Started Prerequisites To run this prebuilt project, you will need: Source Code Change Directory Install Dependencies Note: Composer automatically installs the required dependencies when building the project. Initial Configuration After installing dependencies, you need to set up the basic Laravel configuration: Couchbase Service Provider The CouchbaseServiceProvider class is a Laravel service provider class responsible [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"_acf":"","footnotes":""},"tutorial-languages":[545],"tutorial-tags":[547,546],"tutorial-technologies":[548,549],"tutorial-types":[550],"class_list":["post-10190","tutorials","type-tutorials","status-publish","hentry","tutorial-languages-php","tutorial-tags-laravel","tutorial-tags-rest-api","tutorial-technologies-kv","tutorial-technologies-query","tutorial-types-quickstart"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.8 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Quickstart in Couchbase with PHP and Laravel - Couchbase<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/quickstart-php-laravel\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Quickstart in Couchbase with PHP and Laravel\" \/>\n<meta property=\"og:description\" content=\"Getting Started Prerequisites To run this prebuilt project, you will need: Source Code Change Directory Install Dependencies Note: Composer automatically installs the required dependencies when building the project. Initial Configuration After installing dependencies, you need to set up the basic Laravel configuration: Couchbase Service Provider The CouchbaseServiceProvider class is a Laravel service provider class responsible [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/quickstart-php-laravel\/\" \/>\n<meta property=\"og:site_name\" content=\"Couchbase\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Couchbase\/\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2548\" \/>\n\t<meta property=\"og:image:height\" content=\"1171\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@couchbase\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"11\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/quickstart-php-laravel\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/quickstart-php-laravel\\\/\",\"name\":\"Quickstart in Couchbase with PHP and Laravel - Couchbase\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#website\"},\"datePublished\":\"2025-12-18T07:47:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/quickstart-php-laravel\\\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/quickstart-php-laravel\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/quickstart-php-laravel\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Quickstart in Couchbase with PHP and Laravel\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/\",\"name\":\"Couchbase\",\"description\":\"The Operational Data Platform for AI\u2122\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#organization\"},\"alternateName\":\"Couchbase, Inc.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"de\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#organization\",\"name\":\"Couchbase\",\"alternateName\":\"Couchbase, Inc.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"width\":1129,\"height\":1129,\"caption\":\"Couchbase\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Couchbase\\\/\",\"https:\\\/\\\/x.com\\\/couchbase\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/CouchbaseServer\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/couchbase\\\/\",\"https:\\\/\\\/github.com\\\/couchbase\\\/\",\"https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Couchbase,_Inc.\"],\"description\":\"Couchbase is a database software company headquartered in San Jose, California, providing an operational data platform for AI used by hundreds of global enterprises.\",\"legalName\":\"Couchbase, Inc.\",\"foundingDate\":\"2011-01-01\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Quickstart in Couchbase with PHP and Laravel - Couchbase","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/quickstart-php-laravel\/","og_locale":"de_DE","og_type":"article","og_title":"Quickstart in Couchbase with PHP and Laravel","og_description":"Getting Started Prerequisites To run this prebuilt project, you will need: Source Code Change Directory Install Dependencies Note: Composer automatically installs the required dependencies when building the project. Initial Configuration After installing dependencies, you need to set up the basic Laravel configuration: Couchbase Service Provider The CouchbaseServiceProvider class is a Laravel service provider class responsible [&hellip;]","og_url":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/quickstart-php-laravel\/","og_site_name":"Couchbase","article_publisher":"https:\/\/www.facebook.com\/Couchbase\/","og_image":[{"width":2548,"height":1171,"url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@couchbase","twitter_misc":{"Est. reading time":"11\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/quickstart-php-laravel\/","url":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/quickstart-php-laravel\/","name":"Quickstart in Couchbase with PHP and Laravel - Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/de\/#website"},"datePublished":"2025-12-18T07:47:16+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/quickstart-php-laravel\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/de\/developers\/tutorials\/quickstart-php-laravel\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/quickstart-php-laravel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/"},{"@type":"ListItem","position":2,"name":"Quickstart in Couchbase with PHP and Laravel"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/de\/#website","url":"https:\/\/www.couchbase.com\/de\/","name":"Couchbase","description":"The Operational Data Platform for AI\u2122","publisher":{"@id":"https:\/\/www.couchbase.com\/de\/#organization"},"alternateName":"Couchbase, Inc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/de\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"de"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/de\/#organization","name":"Couchbase","alternateName":"Couchbase, Inc.","url":"https:\/\/www.couchbase.com\/de\/","logo":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/www.couchbase.com\/de\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","contentUrl":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","width":1129,"height":1129,"caption":"Couchbase"},"image":{"@id":"https:\/\/www.couchbase.com\/de\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Couchbase\/","https:\/\/x.com\/couchbase","https:\/\/www.youtube.com\/c\/CouchbaseServer","https:\/\/www.linkedin.com\/company\/couchbase\/","https:\/\/github.com\/couchbase\/","https:\/\/en.wikipedia.org\/wiki\/Couchbase,_Inc."],"description":"Couchbase ist ein in San Jose, Kalifornien, ans\u00e4ssiges Unternehmen f\u00fcr Datenbanksoftware, das eine operative Datenplattform f\u00fcr KI bereitstellt, die von Hunderten von globalen Unternehmen eingesetzt wird.","legalName":"Couchbase, Inc.","foundingDate":"2011-01-01"}]}},"acf":[],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorials\/10190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorials"}],"about":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/types\/tutorials"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorials\/10190\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/media?parent=10190"}],"wp:term":[{"taxonomy":"tutorial-languages","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-languages?post=10190"},{"taxonomy":"tutorial-tags","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-tags?post=10190"},{"taxonomy":"tutorial-technologies","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-technologies?post=10190"},{"taxonomy":"tutorial-types","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-types?post=10190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}