### Installing Recommended Laravel Doctrine Packages (Bash) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/installation.md Installs additional recommended Laravel Doctrine packages (migrations, acl, extensions) via Composer to enable advanced features. ```bash composer require laravel-doctrine/migrations laravel-doctrine/acl laravel-doctrine/extensions ``` -------------------------------- ### Accessing Data in Markdown (Vue Script Setup) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/api-examples.md Demonstrates accessing theme, page, and frontmatter data using the `useData()` API within a ` ## Results ### Theme Data
{{ theme }}
### Page Data
{{ page }}
### Page Frontmatter
{{ frontmatter }}
``` -------------------------------- ### Start Laravel Sail Environment Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/quickstart.md Uses the Sail wrapper script to start the Docker containers required for the Laravel development environment in detached mode (-d). ```bash ./vendor/bin/sail up -d ``` -------------------------------- ### Launch Development Server Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/quickstart.md Executes the 'dev' script defined in the composer.json file, typically used to start the built-in PHP development server for the application. ```bash composer run dev ``` -------------------------------- ### Installing Laravel Doctrine JSON:API Package (Bash) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/installation.md Adds the main sowl/laravel-doctrine-jsonapi package to the project dependencies using Composer, specifically targeting the dev-main branch. ```bash composer require sowl/laravel-doctrine-jsonapi:dev-main ``` -------------------------------- ### Creating New Laravel Project (Bash) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/installation.md Creates a new Laravel project using Composer, specifying version 12.0. This is the initial step if a project doesn't exist. ```bash composer create-project laravel/laravel:^12.0 laravel-jsonapi ``` -------------------------------- ### Accessing Data in Vue Component (Script Setup) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/api-examples.md Shows how to use the `useData()` API within a standard ` ``` -------------------------------- ### Installing Laravel Doctrine ORM (Bash) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/installation.md Installs the core laravel-doctrine/orm package via Composer, which is a required dependency for the JSON:API package. ```bash composer require laravel-doctrine/orm ``` -------------------------------- ### Publishing JSON:API Package Configuration (Bash) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/installation.md Publishes the configuration file (config/jsonapi.php) and the route file (routes/jsonapi.php) for the JSON:API package using the Artisan command. ```bash php artisan vendor:publish --provider="Sowl\JsonApi\JsonApiServiceProvider" ``` -------------------------------- ### Listing Available Routes (Bash) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/installation.md Displays a list of all registered routes in the Laravel application using the Artisan command, useful for verifying the JSON:API endpoints are correctly configured. ```bash php artisan route:list ``` -------------------------------- ### Seeding Database (Bash) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/installation.md Runs database seeders using the Artisan command to populate the database with initial data, often used for testing or default content. ```bash php artisan db:seed ``` -------------------------------- ### Start Development Environment - Shell Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/CLAUDE.md Command to start the main development environment service (typically the application or web server) within the Docker Compose setup. ```Shell docker compose run php ``` -------------------------------- ### Running Doctrine Migrations (Bash) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/installation.md Executes pending Doctrine database migrations using the Artisan command to set up or update the database schema based on defined entities. ```bash php artisan doctrine:migrations:migrate ``` -------------------------------- ### Configuring JSON:API Routes in Laravel 12 (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/installation.md Demonstrates how to register the JSON:API routes within the bootstrap/app.php file for Laravel 12, setting up the route prefix, name prefix, and middleware. ```php use Illuminate\Foundation\Application; use Illuminate\Support\Facades\Route; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', commands: __DIR__.'/../routes/console.php', health: '/up', then: function () { Route::prefix(config('jsonapi.routing.rootPathPrefix', '')) ->name(config('jsonapi.routing.rootNamePrefix', 'jsonapi.')) ->middleware(config('jsonapi.routing.rootMiddleware')) ->group(base_path('routes/jsonapi.php')); }, )->create(); ``` -------------------------------- ### Create Project and Navigate Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/quickstart.md Uses Composer to create a new project based on the laravel-doctrine-jsonapi-skeleton and then changes the current directory into the newly created project folder. ```bash composer create-project sowl/laravel-doctrine-jsonapi-skeleton jsonapi cd jsonapi ``` -------------------------------- ### Fetching Related Resources (JSON:API) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/relationships.md Shows how to retrieve the full resource objects (including attributes) for roles associated with a user using a GET request to the related resources endpoint. Provides complete details for linked resources. ```http GET /api/users/{userId}/roles ``` ```json { "data": [ { "id": "1", "type": "roles", "attributes": { "name": "Root" }, "links": { "self": "/api/roles/1" } }, { "id": "2", "type": "roles", "attributes": { "name": "User" }, "links": { "self": "/api/roles/2" } } /* ... potentially more roles ... */ ] } ``` -------------------------------- ### JavaScript Code with Line Highlighting Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/markdown-examples.md A simple JavaScript object structure, likely for a framework like Vue, used as an example to demonstrate syntax highlighting and specific line highlighting in VitePress markdown. ```javascript export default { data () { return { msg: 'Highlighted!' } } } ``` -------------------------------- ### Run Tests with Sail Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/quickstart.md Executes the application's test suite using the Laravel Sail wrapper script within the Docker environment. ```bash ./vendor/bin/sail test ``` -------------------------------- ### Configure Example Resource Instantiation Strategies in PHP Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/openapi/configurations.md Defines the strategies Scribe should use to generate example model instances for documentation. Configuring 'models_source' with Doctrine strategies ensures examples are created using Doctrine factories or repositories. ```php 'examples' => [ ... 'models_source' => [ 'doctrineFactoryCreate', // 'doctrineFactoryMake', // Optionally enable for non-persisted entities 'doctrineRepositoryFirst', ], ], ``` -------------------------------- ### Install Laravel Doctrine ORM Package (Shell) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Installs the main Laravel Doctrine ORM package using Composer. The -W flag updates dependencies without requiring manual confirmation. Requires Composer installed. ```shell composer require -W laravel-doctrine/orm:^1.8 ``` -------------------------------- ### Run Doctrine Migrations with Sail Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/quickstart.md Executes the Doctrine migrations command using the Laravel Sail wrapper script to apply database schema changes within the Docker environment. ```bash ./vendor/bin/sail artisan doctrine:migrations:migrate ``` -------------------------------- ### Markdown Input for Custom Containers Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/markdown-examples.md Shows the Markdown syntax using ':::' followed by the container type (info, tip, warning, danger, details) to create special blocks in VitePress. ```markdown ::: info This is an info box. ::: ::: tip This is a tip. ::: ::: warning This is a warning. ::: ::: danger This is a dangerous warning. ::: ::: details This is a details block. ::: ``` -------------------------------- ### Fetching To-One Relationship Linkage (HTTP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/relationships.md Explains how to fetch the linkage data (ID and type) for a to-one relationship without fetching the full related resource. Useful for checking if a relationship exists or getting the related resource's identifier. ```HTTP GET /api/userProfiles/{profileId}/relationships/user ``` -------------------------------- ### Example JSON Output for Resource Collection (200 OK) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/responses.md Provides an example of the JSON:API structure for a collection response generated by `response()->collection()`, including `meta` (potentially for pagination), `data` as an array of resource objects, and top-level `links` (for pagination). ```JSON { "meta": { // Example meta added by pagination "page": { "currentPage": 1, "perPage": 15, "total": 50, "lastPage": 4 } }, "data": [ { "type": "users", "id": "1", "attributes": { ... }, "links": { "self": "/api/users/1" } }, { "type": "users", "id": "2", "attributes": { ... }, "links": { "self": "/api/users/2" } } // ... more users ], "links": { // Example links added by pagination "first": "/api/users?page[number]=1", "last": "/api/users?page[number]=4", "prev": null, "next": "/api/users?page[number]=2" } } ``` -------------------------------- ### Fetching Relationship Linkage (JSON:API) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/relationships.md Demonstrates how to fetch only the linkage data (IDs and types) for roles associated with a user using a GET request to the relationships endpoint. Useful for checking associations without retrieving full resource details. ```http GET /api/users/{userId}/relationships/roles ``` ```json { "data": [ { "id": "1", "type": "roles", "links": { "self": "/api/roles/1" } }, { "id": "2", "type": "roles", "links": { "self": "/api/roles/2" } } ] } ``` -------------------------------- ### Implementing Basic UserTransformer Class (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/transformers.md Provides a basic example of a UserTransformer class extending `AbstractTransformer`, implementing the `transform` method to expose user attributes for the JSON:API response, and includes a commented example of an `include` method for handling relationships. ```php $user->getId(), 'name' => $user->getName(), 'email' => $user->getEmail(), 'createdAt' => $user->getCreatedAt()?->toISOString(), // DO NOT include relationship data here. ]; } // Example include method if 'user_profile' relationship exists /* public function includeUserProfile(User $user): ?\League\Fractal\Resource\Item { $profile = $user->getProfile(); return $profile ? $this->item($profile, new UserProfileTransformer(), Profile::getResourceType()) : null; } */ } ``` -------------------------------- ### Real-World Default User Factory Example (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/factories.md A practical example of a default User entity factory taken from a test suite. It demonstrates using specific test entities and shows how relationships can be handled, including using static methods on related entity classes. ```php define(User::class, function (Faker\Generator $faker) { return [ 'id' => $faker->uuid, 'name' => $faker->name, 'email' => $faker->email, 'password' => 'secret', 'status' => entity(UserStatus::class, 'active')->create(), 'roles' => new ArrayCollection([ Role::user(), ]), ]; }); ``` -------------------------------- ### Markdown Input for JavaScript Syntax Highlighting Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/markdown-examples.md Demonstrates the Markdown syntax using backticks and language specifier with line highlighting ({4}) to define a JavaScript code block for VitePress. ```markdown ```js{4} export default { data () { return { msg: 'Highlighted!' } } } ``` ``` -------------------------------- ### Installing Laravel 12.0 Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/README.md Command to create a new Laravel project specifically tailored for compatibility with the package requirements. ```Shell composer create-project laravel/laravel:^12.0 laravel-jsonapi ``` -------------------------------- ### Install Scribe Laravel Package Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/openapi/index.md Installs the Scribe package using Composer, which is a prerequisite for generating API documentation with this package. ```bash composer require knuckleswtf/scribe ``` -------------------------------- ### Real-World Named User Factory Example (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/factories.md A practical example of a named factory variant ('user') for the User entity from a test suite. It shows how to use predefined constants for specific data like IDs and demonstrates consistency with the default factory's relationship handling. ```php $factory->defineAs(User::class, 'user', function (Faker\Generator $faker) { return [ 'id' => User::USER_ID, 'name' => 'testing user1', 'email' => 'test1email@test.com', 'password' => 'secret', 'status' => entity(UserStatus::class, 'active')->create(), 'roles' => new ArrayCollection([ Role::user(), ]), ]; }); ``` -------------------------------- ### JSON:API Response for To-One Relationship Linkage Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/relationships.md Shows the expected JSON structure when fetching the linkage for a to-one relationship. Includes examples for a linked resource (showing ID and type) and for a null relationship (showing data: null). ```JSON { "data": { "id": "8a41dde6-b1f5-4c40-a12d-d96c6d9ef90b", "type": "users" }, "links": { "self": "/api/userProfiles/{profileId}/relationships/user", "related": "/api/userProfiles/{profileId}/user" } } ``` ```JSON { "data": null, "links": { /* ... links ... */ } } ``` -------------------------------- ### Install Laravel Doctrine Migrations Package (Shell) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Installs the Laravel Doctrine Migrations package using Composer. This package provides integration for Doctrine migrations within Laravel. Requires Composer installed. ```shell composer require -W laravel-doctrine/migrations ``` -------------------------------- ### Install Faker Package (Dev) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Installs the Faker library as a development dependency using Composer. Faker is commonly used for generating fake data for testing and seeding. ```Shell composer require fzaninotto/faker --dev ``` -------------------------------- ### Installing Laravel Doctrine JSON:API Package Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/README.md Command to add the main package dependency to your Laravel project using Composer. ```Shell composer require sowl/laravel-doctrine-jsonapi:dev-main ``` -------------------------------- ### Run Doctrine Migrations (Shell) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Executes pending Doctrine migrations, applying database schema changes defined in the migration files. This command updates the database to match the desired schema version. Requires Doctrine Migrations installed and migration files present. ```shell php artisan doctrine:migrations:migrate ``` -------------------------------- ### Install Doctrine Extensions Packages (Shell) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Installs the Laravel Doctrine Extensions package and the required Gedmo and Beberlei Doctrine Extensions libraries via Composer. These provide additional Doctrine functionalities like Timestampable, Sluggable, etc. Requires Composer installed. ```shell composer require laravel-doctrine/extensions composer require "gedmo/doctrine-extensions=^3.0" composer require "beberlei/doctrineextensions=^1.0" ``` -------------------------------- ### Generating JSON:API Response Example (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/openapi/index.md Demonstrates the core process of generating a JSON:API response example using an entity created by a factory and transformed by a resource transformer. This snippet shows the steps involved in preparing data for documentation. ```php $entity = entity($resourceClass)->create(); $transformer = $this->getTransformerForResource($resourceType); $response = this->response()->item($entity, $transformer); ``` -------------------------------- ### Meta-Only Response Example (JSON:API, JSON) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/responses.md Provides an example of the JSON output structure for a meta-only response generated by the ResponseFactory's `meta` method. It shows the top-level `meta` object containing key-value pairs. ```json { "meta": { "status": "operational", "timestamp": "..." } } ``` -------------------------------- ### Fetching Related To-One Resource (HTTP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/relationships.md Explains how to fetch the full resource object for the related entity in a to-one relationship. This is used when you need the attributes and potentially other relationships of the linked resource. ```HTTP GET /api/userProfiles/{profileId}/user ``` -------------------------------- ### Publish Laravel Doctrine Migrations Config (Shell) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Publishes the configuration files for the Laravel Doctrine Migrations package. This allows customization of migration settings. Requires Artisan CLI. ```shell php artisan vendor:publish --tag="config" --provider="LaravelDoctrine\Migrations\MigrationsServiceProvider" ``` -------------------------------- ### Extending AbstractAction for a Show Action (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/api/AbstractAction.md This example demonstrates how to extend `AbstractAction` to create a specific action, `ShowUserAction`. It implements the `handle` method to retrieve a resource from the request and return it as a single item response using the response factory. ```php class ShowUserAction extends AbstractAction { public function handle(): Response { $user = $this->request()->resource(); return $this->response()->item($user); } } ``` -------------------------------- ### Implementing ResourceInterface in PHP Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/api/ResourceInterface.md This snippet shows an example implementation of the `ResourceInterface` for a `User` entity. It demonstrates how to provide the required `getId`, `getResourceType`, and `transformer` methods to make the entity compatible with the JSON:API resource handling. ```php class User implements ResourceInterface { public function getId() { return $this->id; } public function getResourceType() { return 'users'; } public function transformer() { return new UserTransformer(); } } ``` -------------------------------- ### Generate Doctrine Migration Diff (Shell) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Generates a new Doctrine migration file by comparing the current state of the database schema (or mapping information) to the defined Doctrine entity mappings. This command helps create migrations based on entity changes. Requires Doctrine Migrations installed and configured. ```shell php artisan doctrine:migrations:diff ``` -------------------------------- ### Example JSON Output for Single Resource (200 OK) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/responses.md Illustrates the expected JSON:API structure for a single resource response generated by the `response()->item()` method, including `data`, `type`, `id`, `attributes`, and `links`. ```JSON { "data": { "type": "users", "id": "123", "attributes": { "name": "Updated Name", "email": "user@example.com", "createdAt": "..." }, "links": { "self": "/api/users/123" } } } ``` -------------------------------- ### Enable Doctrine Timestampable Extension (PHP Config) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Configures the config/doctrine.php file to enable the TimestampableExtension. This extension automatically updates entity timestamps (created_at, updated_at). Requires the Doctrine Extensions packages installed and config published. ```php 'extensions' => [ //LaravelDoctrine\ORM\Extensions\TablePrefix\TablePrefixExtension::class, LaravelDoctrine\Extensions\Timestamps\TimestampableExtension::class, //LaravelDoctrine\Extensions\SoftDeletes\SoftDeleteableExtension::class, //LaravelDoctrine\Extensions\Sluggable\SluggableExtension::class, //LaravelDoctrine\Extensions\Sortable\SortableExtension::class, //LaravelDoctrine\Extensions\Tree\TreeExtension::class, //LaravelDoctrine\Extensions\Loggable\LoggableExtension::class, //LaravelDoctrine\Extensions\Blameable\BlameableExtension::class, //LaravelDoctrine\Extensions\IpTraceable\IpTraceableExtension::class, //LaravelDoctrine\Extensions\Translatable\TranslatableExtension::class ], ``` -------------------------------- ### Example JSON:API Success Response Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/response.md Illustrates a standard JSON:API success response structure, including the 'data' object with 'type', 'id', and 'attributes'. This format is used when an API request is successful and returns data. ```json { "data": { "type": "users", "id": "1", "attributes": { "name": "John Doe" } } } ``` -------------------------------- ### Example JSON:API Error Response Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/response.md Demonstrates a standard JSON:API error response format, showing an array of error objects. Each error object includes 'status', 'title', and 'detail' to provide clear feedback to the client about issues like validation errors. ```json { "errors": [ { "status": "422", "title": "Validation Error", "detail": "The name field is required." } ] } ``` -------------------------------- ### Register Laravel Doctrine Migrations Service Provider (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Adds the Doctrine Migrations service provider to the providers array in config/app.php. This enables the migration commands and functionality. Requires editing config/app.php. ```php LaravelDoctrine\Migrations\MigrationsServiceProvider::class, ``` -------------------------------- ### Search Filter Query Parameter and Resulting SQL Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/filters.md Demonstrates how a search query parameter (e.g., `filter=q`) is used and the corresponding SQL `LIKE` condition generated when the filter property is set to 'name'. ```Example filter=q ``` ```SQL WHERE alias.name LIKE ('%q%') ``` -------------------------------- ### Register Doctrine Extensions Service Providers (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Adds the service providers for Gedmo and Beberlei Doctrine Extensions to the providers array in config/app.php. This makes the extensions available for use. Requires editing config/app.php. ```php LaravelDoctrine\Extensions\GedmoExtensionsServiceProvider::class, LaravelDoctrine\Extensions\BeberleiExtensionsServiceProvider::class, ``` -------------------------------- ### Requesting Resource Meta Fields (HTTP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/meta.md Demonstrates how to request specific meta fields for a resource type using the `meta` query parameter in an HTTP GET request. It shows requesting the `totalCount` for the `users` resource type. ```http GET /api/resources?meta[users]=totalCount ``` -------------------------------- ### Publish Laravel Doctrine ORM Config (Shell) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Publishes the configuration files for the Laravel Doctrine ORM package to the config directory of the Laravel application. This allows customization of Doctrine settings. Requires Artisan CLI. ```shell php artisan vendor:publish --tag="config" --provider="LaravelDoctrine\ORM\DoctrineServiceProvider" ``` -------------------------------- ### Registering Resource Entity in Config Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/README.md Example of adding a Doctrine entity class (`App\Entities\User`) to the `resources` array in the package's configuration file (`config/jsonapi.php`) to register it as a JSON:API resource. ```PHP 'resources' => [ App\Entities\User::class, ] ``` -------------------------------- ### Defining To-One Relationship in PHP Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/resourceInterface.md Shows how to define a To-One relationship using `ToOneRelationship::create`. This example defines a 'country' relationship to the `Country` entity class. ```php // User Entity public static function relationships(): RelationshipsCollection { return new RelationshipsCollection([ ToOneRelationship::create('country', Country::class) ]); } ``` -------------------------------- ### Extending AbstractTransformer for User Entity (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/api/AbstractTransformer.md This example demonstrates how to extend the `AbstractTransformer` class to create a specific transformer for a `User` entity. It defines the `transform` method to map `User` properties (`id`, `name`) to the desired output format. ```php class UserTransformer extends AbstractTransformer { public function transform(User $user) { return [ 'id' => $user->getId(), 'name' => $user->getName(), ]; } } ``` -------------------------------- ### JSON:API Response for Related To-One Resource Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/relationships.md Shows the expected JSON structure when fetching the full resource object for a related entity in a to-one relationship. Includes the resource object with ID, type, attributes, and links. ```JSON { "data": { "id": "8a41dde6-b1f5-4c40-a12d-d96c6d9ef90b", "type": "users", "attributes": { "email": "test1email@test.com", "name": "testing user1" }, "links": { /* ... links ... */ } /* ... other relationships potentially ... */ } } ``` -------------------------------- ### Defining Named Entity Factory Variant (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/factories.md Demonstrates how to define a named factory variant for an entity. This allows creating entities with specific predefined data sets, useful for generating documentation examples representing different states or roles, like an 'admin' user. ```php // You can also define named variants $factory->defineAs(User::class, 'admin', function (Faker\Generator $faker) { return [ 'name' => 'Admin User', 'email' => 'admin@example.com', 'roles' => new ArrayCollection([ entity(Role::class, 'admin')->create(), ]), ]; }); ``` -------------------------------- ### Configuring SQLite In-Memory Database (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/openapi/index.md Provides the configuration array for setting up an SQLite in-memory database connection within Laravel's config/database.php. This setup is recommended for faster and isolated documentation generation. ```php 'sqlite' => [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ], ``` -------------------------------- ### Adding to To-Many Relationship (JSON:API) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/relationships.md Illustrates how to add one or more resources to a To-Many relationship using a POST request to the relationships endpoint. The request body contains the linkage data for the resources to be added. The response shows the updated complete set of linkages. ```http POST /api/users/{userId}/relationships/roles ``` ```json { "data": [ { "type": "roles", "id": "3" } ] /* Add role with ID '3' */ } ``` ```json { "data": [ { "id": "2", "type": "roles", "links": { "self": "/api/roles/2" } }, /* Existing role */ { "id": "3", "type": "roles", "links": { "self": "/api/roles/3" } } /* Newly added role */ ] } ``` -------------------------------- ### Register Laravel Doctrine ORM Service Provider (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Adds the main Doctrine ORM service provider to the providers array in the Laravel config/app.php file. This registers the necessary services for Doctrine integration. Requires editing config/app.php. ```php LaravelDoctrine\ORM\DoctrineServiceProvider::class, ``` -------------------------------- ### Using ResponseFactory item() Method (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/responses.md Provides examples of using the `response()->item()` method to return a single resource after fetching or updating an entity. This method sets the HTTP status to 200 OK by default. ```PHP // Inside an Action's handle method // Fetching a user $user = $this->rm()->findOrFail(User::getResourceType(), $userId); return $this->response()->item($user); // After updating a user $user->setName($request->input('data.attributes.name')); $this->em()->flush(); return $this->response()->item($user); ``` -------------------------------- ### Requesting Resource and Included Relationship Meta (HTTP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/meta.md Illustrates how to request meta fields for both the primary resource and included relationships in a single HTTP GET request. It uses the `include` parameter along with multiple `meta` parameters for different resource types (`users` and `roles`). ```http GET /api/users/8a41dde6-b1f5-4c40-a12d-d96c6d9ef90b?include=roles&meta[users]=lastLogin&meta[roles]=memberCount ``` -------------------------------- ### Configure Database Server Version (PHP Config) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Adds or updates the serverVersion key for a database connection (e.g., 'mysql') in the config/database.php file. This helps Doctrine determine the correct platform and SQL dialect. Replace '8.0' with your actual database version. ```php 'connections' => [ 'mysql' => [ 'serverVersion' => '8.0', ], ], ``` -------------------------------- ### Clearing To-One Relationship (HTTP/JSON) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/relationships.md Explains how to clear or remove the link to a related resource in a to-one relationship using a PATCH request to the relationships endpoint. The request body contains null for the data. ```HTTP PATCH /api/userProfiles/{profileId}/relationships/user ``` ```JSON { "data": null } ``` -------------------------------- ### Replacing a Relationship (JSON:API) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/relationships.md Demonstrates how to replace the entire set of linked resources in a relationship (To-Many or To-One) using a PATCH request to the relationships endpoint. The request body contains the complete desired set of linkage data. Existing links not in the request are removed. ```http PATCH /api/users/{userId}/relationships/roles ``` ```json { "data": [ { "type": "roles", "id": "2" } ] /* Set roles to only ID '2' */ } ``` ```json { "data": [ { "id": "2", "type": "roles", "links": { "self": "/api/roles/2" } } ] } ``` -------------------------------- ### Configuring Database Transactions for Scribe (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/openapi/index.md Illustrates how to configure which database connections Scribe should wrap in transactions during documentation generation. This snippet shows the setting in config/scribe.php to ensure data created for examples is rolled back. ```php 'database_connections_to_transact' => [config('database.default')], ``` -------------------------------- ### Updating/Replacing To-One Relationship (HTTP/JSON) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/relationships.md Explains how to update or replace the linked resource in a to-one relationship using a PATCH request to the relationships endpoint. The request body contains the linkage data (type and ID) of the new resource to link. ```HTTP PATCH /api/userProfiles/{profileId}/relationships/user ``` ```JSON { "data": { "type": "users", "id": "f1d2f365-e9aa-4844-8eb7-36e0df7a396d" } } ``` -------------------------------- ### Using Entity Factories in Seeders (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/factories.md Provides examples of how to use the defined entity factories within a Doctrine Seeder class. It shows creating single entities using the default factory and named variants, creating entities with overridden attributes, and creating multiple instances. ```php create(); // Create a user with a named factory variant $admin = entity(User::class, 'admin')->create(); // Create an entity with custom attributes $article = entity(Article::class)->create([ 'title' => 'Custom Title', 'author' => $user, ]); // Create multiple entities entity(Article::class, 5)->create([ 'author' => $admin, ]); } } ``` -------------------------------- ### Replace Password Reset Service Provider (PHP Config) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Replaces the default Laravel PasswordResetServiceProvider with the Doctrine-compatible version in config/app.php. This ensures password reset functionality works correctly with Doctrine entities. Requires editing config/app.php. ```php ... 'providers' => [ //Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, LaravelDoctrine\ORM\Auth\Passwords\PasswordResetServiceProvider::class, ] ... ``` -------------------------------- ### Configure Authentication Provider for Doctrine (PHP Config) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Updates the authentication provider configuration in config/auth.php to use the 'doctrine' driver and specify the Doctrine Entity class (\App\Entities\User::class) as the user model. Requires a Doctrine User entity to exist. ```php ... 'providers' => [ 'users' => [ 'driver' => 'doctrine', 'model' => \App\Entities\User::class, ], ] ... ``` -------------------------------- ### Requesting Relationship Endpoint Meta Fields (HTTP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/meta.md Demonstrates requesting meta fields when accessing the relationship endpoint itself using the `meta` query parameter in an HTTP GET request. It requests the `totalCount` for the `roles` relationship endpoint of a specific user. ```http GET /api/users/8a41dde6-b1f5-4c40-a12d-d96c6d9ef90b/relationships/roles?meta[roles]=totalCount ``` -------------------------------- ### Add Failed Jobs Service Provider (PHP Config) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Adds the FailedJobsServiceProvider provided by Laravel Doctrine ORM to the providers array in config/app.php. This integrates Doctrine with Laravel's queue failed jobs functionality. Requires editing config/app.php. ```php ... 'providers' => [ LaravelDoctrine\ORM\Queue\FailedJobsServiceProvider::class, ] ... ``` -------------------------------- ### Testing JSON:API Resource View Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/README.md A feature test example demonstrating how to test viewing a user resource endpoint, including checking for authorization (403 status) and successful authorized access (200 status) with JSON structure assertion. ```PHP public function test_view_user() { $user = entity(User::class)->create(); $this->json('get', '/jsonapi/users/'.$user->getId())->assertStatus(403); $this->actingAs($user); $this->json('get', '/jsonapi/users/'.$user->getId()) ->assertStatus(200) ->assertJson([ 'data' => [ 'id' => (string) $user->getId(), 'type' => 'users' ] ]); } ``` -------------------------------- ### Requesting Relationship Meta Fields (HTTP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/meta.md Shows how to request meta fields specifically for a relationship endpoint of a resource using the `meta` query parameter in an HTTP GET request. It requests `count` and `lastUpdated` for the `roles` relationship of a specific user. ```http GET /api/users/8a41dde6-b1f5-4c40-a12d-d96c6d9ef90b/roles?meta[roles]=count,lastUpdated ``` -------------------------------- ### Using InteractWithDoctrineDatabase Trait in Laravel Tests Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/testing.md Illustrates how to use the `InteractWithDoctrineDatabase` trait in a Laravel test case. It includes the `use` statement and calls the `interactsWithDoctrineDatabase` method in the `setUp` method to synchronize Doctrine and Laravel database connections, enabling Laravel DB assertions. ```php use Sowl\JsonApi\Testing\InteractWithDoctrineDatabase; class MyTestCase extends TestCase { use InteractWithDoctrineDatabase; protected function setUp(): void { parent::setUp(); $this->interactsWithDoctrineDatabase(); } } ``` -------------------------------- ### Using DoctrineRefreshDatabase Trait in Laravel Tests Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/testing.md Demonstrates how to include and use the `DoctrineRefreshDatabase` trait in a Laravel test case. It shows adding the `use` statement for the trait and calling the `refreshDoctrineDatabase` method within the `setUp` method to ensure a clean schema before each test. ```php use Sowl\JsonApi\Testing\DoctrineRefreshDatabase; class MyTestCase extends TestCase { use DoctrineRefreshDatabase; protected function setUp(): void { parent::setUp(); $this->refreshDoctrineDatabase(); } } ``` -------------------------------- ### Removing from To-Many Relationship (JSON:API) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/relationships.md Shows how to remove specific resources from a To-Many relationship using a DELETE request to the relationships endpoint. The request body contains the linkage data for the resources to be removed. The response shows the remaining set of linkages. ```http DELETE /api/users/{userId}/relationships/roles ``` ```json { "data": [ { "type": "roles", "id": "1" } ] /* Remove role with ID '1' */ } ``` ```json { "data": [ { "id": "2", "type": "roles", "links": { "self": "/api/roles/2" } } /* The other role remains */ ] } ``` -------------------------------- ### Documenting JSON:API Relationship Request with Scribe (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/openapi/attributes.md This snippet demonstrates using the #[ResourceRequestRelationships] attribute to document a controller method handling JSON:API relationship requests (e.g., /users/{id}/relationships/{relation}). It specifies the resource type, ID type, example ID, and route parameter name. ```php #[ResourceRequestRelationships(resourceType: 'users', idType: 'string', idExample: 'abc123', idParam: 'id')] public function relationships($id, $relationship) {} ``` -------------------------------- ### Running Scribe with SQLite Connection (Bash) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/openapi/index.md Shows the command line instruction to run the Scribe documentation generation process while explicitly setting the database connection to the configured 'sqlite' connection. This is typically done via an environment variable or a dedicated .env.docs file. ```bash DB_CONNECTION=sqlite php artisan scribe:generate ``` -------------------------------- ### Publishing JSON:API Package Configuration Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/README.md Run this Artisan command to publish the package's configuration files, allowing you to customize settings like routing prefixes and resource registration. ```Shell php artisan vendor:publish --provider="Sowl\JsonApi\JsonApiServiceProvider" ``` -------------------------------- ### Configure Search Filter Property in PHP Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/filters.md Sets the entity property that the search filter will operate on within the list action. The example configures the filter to target the 'name' property. ```PHP setFilterProperty('name') ``` -------------------------------- ### Implementing User Resource with Laravel Doctrine JSON:API (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/resources.md Demonstrates how to define a basic User entity as a JSON:API resource by implementing the `Sowl\JsonApi\ResourceInterface`. It shows the required methods (`getId`, `getResourceType`, `transformer`, `relationships`) needed to conform to the JSON:API specification. ```php #[ORM\Entity] #[ORM\Table(name: 'users')] class User implements ResourceInterface { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: 'integer')] private ?int $id = null; #[ORM\Column(type: 'string')] private string $name; #[ORM\Column(type: 'string', unique: true)] private string $email; // Other properties and methods... /** * Returns the unique identifier for the resource. MUST be a string. */ public function getId(): string { return (string) $this->id; } /** * Returns the JSON:API resource type. */ public static function getResourceType(): string { return 'users'; } /** * Returns the FQCN of the transformer for this resource. */ public static function transformer(): string { return UserTransformer::class; } /** * Defines the relationships for this resource. * Use the WithRelationships trait for easier management. */ public static function relationships(): RelationshipsCollection { // See Relationships documentation for how to define these. // For a basic user, maybe it's initially empty or has common ones. return new RelationshipsCollection([]); } } ``` -------------------------------- ### Implementing Resource Access Policies for Admin (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/policies.md Implement `viewAny` and `create` policy methods to control access to listing and creating resources, restricting these actions to users with administrative privileges. Requires `User`. ```php public function viewAny(User $user): bool { return $user->isAdmin(); } public function create(User $user): bool { return $user->isAdmin(); } ``` -------------------------------- ### Apply ResourceRequest Attribute to Method - PHP Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/openapi/attributes.md Illustrates applying the ResourceRequest attribute to a controller method to specify the resource type, ID type, and an example ID for a single-resource request endpoint. ```php #[ResourceRequest(resourceType: 'users', idType: 'string', idExample: 'abc123')] public function show($id) {} ``` -------------------------------- ### Enter Development Container - Shell Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/CLAUDE.md Command to enter the running Docker container for interactive development and debugging within the project environment. ```Shell docker compose run php sh ``` -------------------------------- ### Run Tests with Coverage - Shell Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/CLAUDE.md Command to execute PHPUnit tests and generate an HTML code coverage report in the specified output directory. ```Shell docker compose run php phpunit --coverage-html ./tests/coverage ``` -------------------------------- ### Run All Tests - Shell Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/CLAUDE.md Command to execute the complete PHPUnit test suite for the package within the isolated Docker container environment. ```Shell docker compose run php phpunit ``` -------------------------------- ### Defining a New Seeder Class in PHP Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/workbench/database/seeders/README.md This snippet shows the basic structure for creating a new seeder class. Seeders are used to populate the database with initial data. The main logic resides within the public `run` method, which receives the `EntityManager` as a dependency. ```php class NewSeeder { public function run(EntityManager $em): void { // ... } } ``` -------------------------------- ### Delete Default Laravel Migrations (Shell) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Removes the default migration files created by Laravel in the database/migrations directory. This is done when switching to Doctrine Migrations to avoid conflicts. Use with caution as it deletes files. ```shell rm -rf database/migrations/*.php ``` -------------------------------- ### JSON:API Response with Resource Meta (JSON) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/meta.md Shows a sample JSON:API response including the requested `meta` object for the primary resource (`users`). The `meta` object contains the `totalCount` field as requested in the corresponding HTTP request. ```json { "data": { "id": "8a41dde6-b1f5-4c40-a12d-d96c6d9ef90b", "type": "users", "attributes": { "email": "test1email@test.com", "name": "testing user1" }, "meta": { "totalCount": 42 } } } ``` -------------------------------- ### Generate API Documentation with Scribe Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/openapi/index.md Runs the Scribe command to generate the API documentation based on the configured strategies, attributes, validation rules, and entity factories. ```bash php artisan scribe:generate ``` -------------------------------- ### Defining To-Many Relationship in PHP Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/resourceInterface.md Shows how to define a To-Many relationship using `ToManyRelationship::create`. This example defines a 'roles' relationship to the `Role` entity class, specifying the 'users' mappedBy field. ```php // User Entity public static function relationships(): RelationshipsCollection { return new RelationshipsCollection([ ToManyRelationship::create('roles', Role::class, 'users') ]); } ``` -------------------------------- ### Configuring JSON:API Routes in Bootstrap Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/README.md Demonstrates how to register the package's route file (`routes/jsonapi.php`) within the Laravel 12.x `bootstrap/app.php` using the `withRouting` method, applying configurable prefixes, names, and middleware. ```PHP use Illuminate\Foundation\Application; use Illuminate\Support\Facades\Route; return Application::configure(basePath: dirname(__DIR__)) ->withRouting( web: __DIR__.'/../routes/web.php', commands: __DIR__.'/../routes/console.php', health: '/up', then: function () { Route::prefix(config('jsonapi.routing.rootPathPrefix', '')) ->name(config('jsonapi.routing.rootNamePrefix', 'jsonapi.')) ->middleware(config('jsonapi.routing.rootMiddleware')) ->group(base_path('routes/jsonapi.php')); }, )->create(); ``` -------------------------------- ### Registering and Accessing Resources with ResourceManager (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/api/ResourceManager.md This snippet demonstrates how to obtain an instance of the ResourceManager, register a specific resource class (App\Entities\User), and retrieve the list of all registered resources. ```php $rm = app(ResourceManager::class); $rm->registerResource(App\Entities\User::class); $allResources = $rm->resources(); ``` -------------------------------- ### Configuring Resources in Laravel Doctrine JSON:API (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/configuration.md This snippet shows how to configure the `resources` option in the `config/jsonapi.php` file. It lists the Doctrine entity classes that should be managed as JSON:API resources by the package. Each class must implement `ResourceInterface`. ```PHP 'resources' => [ App\Entities\User::class, ], ``` -------------------------------- ### Transforming Product Entity Attributes (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/concepts/transformers.md Demonstrates the core `transform` method within a hypothetical ProductTransformer, showing how to extract attributes from a Doctrine entity and map them to the JSON:API `attributes` object, including handling nested value objects. ```php // Inside a hypothetical ProductTransformer public function transform(Product $product): array { return [ 'sku' => $product->getSku(), 'name' => $product->getName(), 'price' => $product->getPrice()->getAmount(), // Assuming a Price object 'currency' => $product->getPrice()->getCurrency(), ]; } ``` -------------------------------- ### Remove Default Factories and Seeders Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/advanced/LaravelDoctrine.md Deletes the default factory and seeder files generated by Laravel in the database directory. This is often done when using custom factory/seeder implementations like Laravel Doctrine's Entity Factories. ```Shell rm -rf database/factories/*.php rm -rf database/seeders/*.php ``` -------------------------------- ### JSON:API Response with Resource and Included Relationship Meta (JSON) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/meta.md Provides a sample JSON:API response containing meta fields for both the primary resource (`users`) and an included relationship (`roles`). The response includes the `meta` object within the primary resource and within the included resource object. ```json { "data": { "id": "8a41dde6-b1f5-4c40-a12d-d96c6d9ef90b", "type": "users", "attributes": { "email": "test1email@test.com", "name": "testing user1" }, "relationships": { "roles": { "data": [ { "id": "2", "type": "roles" } ], "links": { "self": "/users/8a41dde6-b1f5-4c40-a12d-d96c6d9ef90b/relationships/roles", "related": "/users/8a41dde6-b1f5-4c40-a12d-d96c6d9ef90b/roles" } } }, "meta": { "lastLogin": "2023-06-15T10:30:00Z" } }, "included": [ { "id": "2", "type": "roles", "attributes": { "name": "admin" }, "meta": { "memberCount": 5 } } ] } ``` -------------------------------- ### Restrict Scribe Docs Access with Middleware in PHP Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/openapi/configurations.md Applies Laravel middleware to the Scribe documentation routes to restrict access. This example uses the 'auth' middleware to ensure only authenticated users can view the API documentation. ```php 'laravel' => [ ... 'middleware' => ['auth'], // Only authenticated users can view docs ], ``` -------------------------------- ### Defining Default Entity Factory (PHP) Source: https://github.com/scholarshipowl/laravel-doctrine-jsonapi/blob/main/docs/guides/factories.md Illustrates how to define a default factory for a Doctrine entity using Laravel Doctrine's factory system. It shows how to populate basic attributes and handle relationships and collections using the `entity()` helper and `ArrayCollection`. ```php define(User::class, function (Faker\Generator $faker) { return [ 'id' => $faker->uuid, 'name' => $faker->name, 'email' => $faker->email, 'password' => 'secret', // For entity relationships, use the entity() helper 'status' => entity(UserStatus::class, 'active')->create(), // For collections, create ArrayCollection instances 'roles' => new ArrayCollection([ entity(Role::class)->create(), ]), ]; }); ```