### PHP API Versioning Example: Product Creation Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/resources/versions.md Demonstrates API versioning for product creation in PHP using Laniakea. It includes a controller, request validation, an action for business logic, and a transformer for response formatting. This example showcases how different versions of requests and responses can be handled while maintaining a consistent business logic layer. ```php create($request); return response()->json( (new ProductTransformer())->toArray($product) ); } } ``` ```php 'required|string|max:255', 'product_price' => 'required|numeric', ]; } } ``` ```php Str::orderedUuid()->toString(), 'name' => $request->input('product_name'), 'price' => $request->integer('product_price') * 100, // Store price in cents. ]); } } ``` ```php $product->id, 'name' => $product->name, 'price' => $product->price / 100, // Display price in dollars. ]; } } ``` -------------------------------- ### Install Laniakea and Publish Configuration Source: https://context7.com/tzurbaev/laniakea-docs/llms.txt This snippet shows the Composer command to install the Laniakea package and the Artisan command to publish its configuration file. ```bash composer require laniakea/laniakea php artisan vendor:publish --provider="Laniakea\LaniakeaServiceProvider" ``` -------------------------------- ### Custom Resource Request for Filter Handling (PHP) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/resources/manager.md Provides a PHP code example demonstrating how to extend the `ResourceRequest` class to customize how filters are retrieved from the request. This example assumes filters are nested under a 'filters' query parameter. ```php getRequest()->input('filters'); return is_array($values) ? Arr::only($values, $filters) : []; } } ``` -------------------------------- ### Install Laniakea Package via Composer Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/getting-started.md Installs the Laniakea package into your Laravel project using Composer. Ensure you have a compatible Laravel and PHP version. ```bash composer require laniakea/laniakea ``` -------------------------------- ### String Setting Example Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/settings/types.md Demonstrates the StringSetting for storing string values. It accepts a default string value and optionally allows empty strings as valid input by setting the second constructor argument to true. ```php first(function ($query) { // Example: Add a condition to the query // $query->where('status', 'active'); // return $query->first(); // Or return the result directly if the method expects it }); ``` -------------------------------- ### Possible Value Setting Example Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/settings/types.md Shows how to implement PossibleValueSetting, which allows storing one of a predefined list of values, similar to an EnumSetting but without strict enum class adherence. It requires a default value and a list of allowed values. ```php first(function (RepositoryQueryBuilderInterface $query) { $query->with(['posts.comments', 'media'])->orderBy('created_at', 'desc')->orderBy('name')->addCriteria([ new WhereLikeCriterion('email', 'hello%') ]); }); ``` -------------------------------- ### Create and Configure ToggleField in PHP Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/forms/fields.md Illustrates the creation of a ToggleField in PHP, used for binary on/off states. The example shows setting the label and a descriptive hint. ```php setHint('Toggle to enable dark mode in admin panel.'); ``` -------------------------------- ### Get First Model or Fail (PHP) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/repositories.md Explains how to use the `firstOrFail()` method to retrieve the first model matching the query criteria, or throw a `ModelNotFoundException` if no results are found. It accepts the same callback as the `first()` method for query manipulation. ```php try { $user = $usersRepository->first(function (RepositoryQueryBuilderInterface $query) { $query->with(['posts.comments', 'media'])->orderBy('created_at', 'desc')->orderBy('name')->addCriteria([ new WhereLikeCriterion('email', 'hello%') ]); }); } catch (ModelNotFoundException $e) { // Such user does not exist. } ``` -------------------------------- ### PHP: Configure BooleanSetting with a default boolean value Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/settings/types.md Shows how to implement the BooleanSetting in PHP to manage boolean configuration values. This example demonstrates setting a default true or false value for the setting. ```php list(function (RepositoryQueryBuilderInterface $query) { $query->with(['posts.comments', 'media'])->orderBy('created_at', 'desc')->orderBy('name')->addCriteria([ new WhereLikeCriterion('email', 'hello%') ]); }); ``` -------------------------------- ### Apply Criterion with Constructor Arguments (PHP) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/repositories/criteria.md Demonstrates how to apply a criterion that requires constructor arguments, such as `UserRoleCriterion`, by passing dynamic values from an HTTP request. This example fetches users based on a role specified in the request. ```php list(function (RepositoryQueryBuilderInterface $query) use ($request) { $query->addCriteria([ new UserRoleCriterion($request->input('role', 'user')), ]); }); return response()->json($users); } } ``` -------------------------------- ### Settings Creation API Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/settings.md This API provides methods to get settings for creating new entities. It allows either using default settings or providing a specific set of initial settings. ```APIDOC ## `getSettingsForCreate` ### Description This method accepts the class name of your settings enum and an optional list of current settings to save. If the second argument is `null`, it will use default values from the settings enum. ### Method This is a conceptual method, not a direct HTTP endpoint. It's typically called within your application logic. ### Endpoint N/A (Application Logic) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php 'John Doe', 'settings' => $settingsValues->getSettingsForCreate( UserSetting::class, null, // Or an array of settings ), ]); ``` ### Response #### Success Response (200) Returns an array of settings values, merged with defaults if provided. #### Response Example ```json { "example": "// Example response structure depends on UserSetting definition" } ``` ``` -------------------------------- ### Model Settings Implementation in PHP with Laniakea Source: https://context7.com/tzurbaev/laniakea-docs/llms.txt Implements settings on Eloquent models using decorators for structured access and modification. This example shows how to integrate Laniakea's settings functionality into your models, providing a clean interface for managing user preferences. It utilizes the CreatesSettingsDecorators trait and HasSettingsInterface. ```php 'array']; public function getSettingsEnum(): string { return UserSetting::class; } public function getCurrentSettings(): ?array { return $this->settings; } public function updateSettings(array $settings): void { $this->update(['settings' => $settings]); } public function getSettingsDecorator(bool $fresh = false): UserSettingsDecorator { return $this->makeSettingsDecorator(UserSettingsDecorator::class, $fresh); } } // Usage $user = User::find(1); if ($user->getSettingsDecorator()->isDarkModeEnabled()) { // Apply dark mode } // Update settings with structured data $user->getSettingsDecorator()->update([ 'ui' => ['dark_mode' => true], 'notifications' => ['list' => [NotificationType::ORDER_CREATED]], ]); ``` -------------------------------- ### Creating Repository Criteria in PHP Source: https://context7.com/tzurbaev/laniakea-docs/llms.txt Explains how to define and use reusable query conditions called Criteria in Laniakea. The example shows a `UserRoleCriterion` that filters users by role. Criteria implement the `RepositoryCriterionInterface` and are applied to repository queries using the `addCriteria` method. This requires the `IlluminateDatabaseEloquentBuilder` and `LaniakeaRepositoriesInterfacesRepositoryCriterionInterface`. ```php where('role', $this->role); } } // Usage in repository or controller $users = $repository->list(function (RepositoryQueryBuilderInterface $query) { $query->addCriteria([ new UserRoleCriterion('admin'), new OnlyActiveUsersCriterion(), ]); }); ``` -------------------------------- ### Use Laniakea Middleware in Routes Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/getting-started.md Applies the Laniakea middleware to route groups in Laravel. The SetResourceRequest middleware is applied to a base group, and SetApiVersion is applied to nested groups with specific version prefixes. This example shows how to structure API routes with versioning. ```php ['laniakea.request']], function () { Route::group(['/prefix' => '/v1', 'middleware' => ['laniakea.version:v1']], function () { // V1 routes }); Route::group(['/prefix' => '/v2', 'middleware' => ['laniakea.version:v2']], function () { // V2 routes }); // Routes without versioning }); ``` -------------------------------- ### Create User Settings with getSettingsForCreate (PHP) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/settings.md Demonstrates how to use the `getSettingsForCreate` method to initialize user settings. It shows two scenarios: one using default settings and another providing custom initial settings. This method requires the settings enum class name and an optional array of settings. ```php 'John Doe', 'settings' => $settingsValues->getSettingsForCreate( UserSetting::class, null, ), ]); ``` ```php 'John Doe', 'settings' => $settingsValues->getSettingsForCreate( UserSetting::class, [ // Use array structure that you would pass to `update()` method. 'ui' => [ 'dark_mode' => true, ], ], ), ]); ``` -------------------------------- ### Get API Version from Service Container Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/getting-started.md Retrieves the current API version name from Laravel's Service Container after the SetApiVersion middleware has been applied. This demonstrates how to access the bound ApiVersionInterface instance. ```php getName(); // $version in 'v1'. ``` -------------------------------- ### Publish Laniakea Configuration File Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/getting-started.md Publishes the Laniakea configuration file to your Laravel project, allowing customization of resource registrars and settings. This command uses the Artisan vendor:publish command with the Laniakea service provider. ```bash php artisan vendor:publish --provider="Laniakea\LaniakeaServiceProvider" ``` -------------------------------- ### Filter Resources by Query Parameters Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/resources/manager.md Demonstrates how to filter resources using query parameters like 'name', 'role', and combining multiple filters with an 'AND' operator. This is useful for retrieving specific subsets of data. ```URL https://example.org/users?name=John https://example.org/users?role=admin https://example.org/users?name=John&role=admin ``` -------------------------------- ### Register Laniakea Middleware in Laravel Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/getting-started.md Registers the SetResourceRequest and SetApiVersion middleware for Laniakea within the Laravel application configuration. This is done in the bootstrap/app.php file and ensures the middleware is available for use in routes. The middleware aliases are defined using the alias method on the Middleware object. ```php withRouting( web: __DIR__.'/../routes/web.php', commands: __DIR__.'/../routes/console.php', health: '/up', ) ->withMiddleware(function (Middleware $middleware) { // Register aliases for Laniakea middleware. $middleware->alias([ 'laniakea.request' => SetResourceRequest::class, 'laniakea.version' => SetApiVersion::class, ]); }) ->withExceptions(function (Exceptions $exceptions) { // })->create(); ``` -------------------------------- ### Configure Middleware Priority in Laravel Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/getting-started.md This snippet demonstrates how to configure middleware priority in a Laravel application using Laniakea's MiddlewarePriorityManager. It ensures that Laniakea's SetResourceRequest and SetApiVersion middleware are executed before Laravel's SubstituteBindings middleware. This is crucial for correct request processing in Laniakea-based applications. ```php withRouting( web: __DIR__.'/../routes/web.php', commands: __DIR__.'/../routes/console.php', health: '/up', ) ->withMiddleware(function (Middleware $middleware) { // Register aliases for Laniakea middleware. $middleware->alias([ 'laniakea.request' => SetResourceRequest::class, 'laniakea.version' => SetApiVersion::class, ]); // Create fresh middleware priority manager with default middleware priority. $manager = MiddlewarePriorityManager::withDefaults($middleware); // Place SetResourceRequest and SetApiVersion middleware before SubstituteBindings middleware. $manager->before(SubstituteBindings::class, [ SetResourceRequest::class, SetApiVersion::class, ]); }) ->withExceptions(function (Exceptions $exceptions) { // })->create(); ``` -------------------------------- ### Configure Exception Handling in Laravel with Laniakea Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/getting-started.md This code configures exception handling in a Laravel application to manage Laniakea's exceptions. It disables reporting for Laniakea's BaseHttpException and registers renderers for both BaseHttpException and Laravel's ValidationException using Laniakea's ExceptionRenderer. This ensures exceptions are rendered in the format expected by Laniakea. ```php withRouting( web: __DIR__.'/../routes/web.php', commands: __DIR__.'/../routes/console.php', health: '/up', ) ->withMiddleware(function (Middleware $middleware) { // }) ->withExceptions(function (Exceptions $exceptions) { /** @var ExceptionRenderer $renderer */ $renderer = app(ExceptionRenderer::class); // Disable reporting for all Lanikea exceptions. $exceptions->dontReport(BaseHttpException::class); // Allow Laniakea's ExceptionRenderer render base exceptions $exceptions->renderable(fn (BaseHttpException $e, Request $request) => $renderer->render($e, $request)); // Optionally: render Laravel's ValidationException with Laniakea's renderer. $exceptions->renderable(fn (ValidationException $e, Request $request) => $renderer->renderValidationException($e, $request)); })->create(); ``` -------------------------------- ### Paginate Resources with 'page' and 'count' Parameters Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/resources/manager.md Shows how to control pagination by specifying the desired page number using the 'page' parameter and the number of records per page using the 'count' parameter. ```URL https://example.org/users?page=2&count=10 ``` -------------------------------- ### Customized Resource Request Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/resources/manager.md Example of extending `ResourceRequest` to customize how filters are retrieved from the request, such as grouping them under a `filters` parameter. ```APIDOC ## Customizing Filter Retrieval ### Description Demonstrates how to create a custom `ResourceRequest` to handle filter parameters differently, for example, by nesting them under a `filters` query parameter. ### Method POST/GET (applies to any method where filters are used) ### Endpoint /users (example) ### Request Body/Query Parameters (Customized) - **filters[name]** (string) - Optional - Filter by name. - **filters[role]** (string) - Optional - Filter by role. ### Request Example (Customized) ``` GET /users?filters[name]=John&filters[role]=admin ``` ### Code Example (PHP) ```php getRequest()->input('filters'); return is_array($values) ? Arr::only($values, $filters) : []; } } ``` ### Note Ensure your `CustomizedResourceRequest` is registered with the resource manager to use this custom behavior. ``` -------------------------------- ### Load Relationships with 'with' Parameter Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/resources/manager.md Explains how to load related resources using the 'with' query parameter. Supports loading single relationships, nested relationships, and multiple relationships separated by commas. ```URL https://example.org/users?with=posts https://example.org/users?with=posts.comments https://example.org/users?with=posts.comments,avatar ``` -------------------------------- ### Implement a Laniakea Resource Filter Source: https://context7.com/tzurbaev/laniakea-docs/llms.txt Implements a resource filter for narrowing down resource lists based on query parameters. This example shows how to apply a 'like' condition to the 'email' column. ```php getQueryBuilder()->where('email', 'like', $value . '%'); } } ``` -------------------------------- ### Add Custom Resource Registrar Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/configuration.md Example of how to add a custom resource registrar to the Laniakea configuration. This involves adding the fully-qualified class name (FQCN) of your registrar to the `registrars` array. ```php [ App\Resources\Registrars\UsersRegistrar::class, ], ]; ``` -------------------------------- ### Create HiddenField in PHP Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/forms/fields.md Provides a simple example of creating a HiddenField in PHP. Hidden fields are used to submit data that is not visible to the user, such as IDs or tokens. ```php getItem( id: $id, request: $request, resource: new UsersResource(), repository: new UsersRepository(), ); return response()->json($user); } } ``` -------------------------------- ### Create Eloquent Model using Repository (PHP) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/repositories.md Shows how to create a new Eloquent model instance using the `create()` method of a Laniakea repository. ```php create([ 'name' => 'John Doe', 'email' => 'john@example.org', 'password' => 'secretsecret', ]); ``` -------------------------------- ### Bind Product Resources - PHP Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/resources/versions.md This snippet shows how to bind a product resource and its corresponding repository using Laniakea's dependency injection binder. It's essential for setting up resource management within the application. ```php $binder->bind('product', ProductsResource::class, ProductsRepository::class); } } ``` -------------------------------- ### Create Laniakea Repository (PHP) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/repositories.md Demonstrates how to create a custom repository by extending the AbstractRepository class and specifying the model class. ```php new SearchFilter(['name']), 'category_id' => new ProductsCategoryFilter(), ]; } public function getInclusions(): array { return [ 'category' => ['category'], 'images' => ['images'], ]; } public function getSorters(): array { return [ 'id' => new ColumnSorter(), 'name' => new ColumnSorter(), ]; } } ``` -------------------------------- ### Define Form HTTP Method (PHP) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/forms.md Specifies the HTTP method (e.g., POST, GET) for form submission by implementing the `getMethod()` method in a form class. This is crucial for backend processing of form data. ```php getPaginator( request: $request, resource: new UsersResource(), repository: new UsersRepository(), callback: fn (RepositoryQueryBuilderInterface $query) => $query->addCriteria([ new OnlyActiveUsersCriterion(), ]), ); return response()->json($paginator); } } ``` -------------------------------- ### PHP: Configure ArraySetting with default, allowed values, and empty array option Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/settings/types.md Demonstrates how to use the ArraySetting in PHP to store array values. It shows how to set a default array, define a list of allowed values for array elements, and control whether empty arrays are permitted. ```php getValue(UserSetting::DARK_MODE) === true; } public function getEnabledNotifications(): array { return $this->getValue(UserSetting::ENABLED_NOTIFICATIONS, []); } public function getEmailSignature(): ?string { return $this->getValue(UserSetting::EMAIL_SIGNATURE); } } ``` -------------------------------- ### Apply Criteria to Repository Query (PHP) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/repositories/criteria.md Illustrates how to apply a custom criterion, `OnlyActiveUsersCriterion`, to a repository query using the `addCriteria()` method within a callback. This example fetches a list of active users. ```php $repository = app(UsersRepository::class); $activeUsers = $repository->list(function (RepositoryQueryBuilderInterface $query) { $query->addCriteria([ new OnlyActiveUsersCriterion(), ]); }); ``` -------------------------------- ### Limit and Skip Results in Repository Query (PHP) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/repositories.md Demonstrates how to limit the number of results returned by a query using the `limit()` method. You can specify the number of items to take and optionally the number of rows to skip. This is useful for pagination or fetching specific subsets of data. ```php $users = $usersRepository->list(function (RepositoryQueryBuilderInterface $query) { $query->with(['posts.comments', 'media'])->orderBy('created_at', 'desc')->orderBy('name')->addCriteria([ new WhereLikeCriterion('email', 'hello%') ])->limit(10, 15); }); ``` -------------------------------- ### Override Default Bindings in Laniakea Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/configuration.md Demonstrates how to override default class bindings within the Laniakea framework. This is useful for substituting default managers with custom implementations. The example shows replacing the default FormsManagerInterface implementation with a custom one. ```php return [ 'bindings' => [ Laniakea\Resources\Interfaces\ResourceManagerInterface::class => Laniakea\Resources\ResourceManager::class, Laniakea\Forms\Interfaces\FormIdsGeneratorInterface::class => Laniakea\Forms\FormIdsGenerator::class, Laniakea\Forms\Interfaces\FormsManagerInterface::class => Laniakea\Forms\FormsManager::class, // [!code --] Laniakea\Forms\Interfaces\FormsManagerInterface::class => App\Forms\CustomFormsManager::class, // [!code ++] Laniakea\Settings\Interfaces\SettingsGeneratorInterface::class => Laniakea\Settings\SettingsGenerator::class, Laniakea\Settings\Interfaces\SettingsUpdaterInterface::class => Laniakea\Settings\SettingsUpdater::class, Laniakea\Settings\Interfaces\SettingsValuesInterface::class => Laniakea\Settings\SettingsValues::class, ], ]; ``` -------------------------------- ### Reading Settings using Decorator (PHP) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/settings.md Demonstrates how to retrieve and use the settings decorator instance from a model to read specific settings. It shows how to call methods defined in the custom decorator, like `isDarkModeEnabled()`. ```php getSettingsDecorator()->isDarkModeEnabled()) { // Dark mode is enabled. } ``` -------------------------------- ### Repository CRUD Operations in PHP Source: https://context7.com/tzurbaev/laniakea-docs/llms.txt Demonstrates how to perform Create, Read, Update, and Delete (CRUD) operations using Laniakea's repository pattern. It covers creating new models, updating existing ones, finding models by ID, listing with filtering and sorting, pagination, and deleting models. This functionality relies on the UsersRepository and RepositoryQueryBuilderInterface. ```php create([ 'name' => 'John Doe', 'email' => 'john@example.org', 'password' => bcrypt('secret'), ]); // Update an existing model $user = $repository->update($user->id, [ 'name' => 'Jane Doe', ]); // Find by ID (returns null if not found) $user = $repository->find(1); // Find or fail (throws ModelNotFoundException) $user = $repository->findOrFail(1); // List with filtering, sorting, and relationships $users = $repository->list(function (RepositoryQueryBuilderInterface $query) { $query->with(['posts', 'avatar']) ->orderBy('created_at', 'desc') ->limit(10, 0); }); // Paginate results $paginator = $repository->paginate( count: 15, page: 1, callback: fn (RepositoryQueryBuilderInterface $query) => $query->orderBy('name'), ); // Delete a model $repository->delete($user->id); ``` -------------------------------- ### API Versioning with Laniakea PHP Source: https://context7.com/tzurbaev/laniakea-docs/llms.txt Demonstrates how to bind different service implementations to the container per API version. This allows for managing multiple versions of your API within the same application. It utilizes Laniakea's VersionBinderInterface for version registration and ResourceRouteBinderInterface for route configuration. ```php bind('v1', [ StoreProductRequestInterface::class => StoreProductRequest::class, ProductTransformerInterface::class => ProductTransformer::class, ], isDefault: true); $binder->bind('v2', [ StoreProductRequestInterface::class => StoreProductRequestV2::class, ProductTransformerInterface::class => ProductTransformerV2::class, ]); } public function bindRoute(ResourceRouteBinderInterface $binder): void { // Route binding configuration } } // Routes configuration Route::group(['middleware' => ['laniakea.request']], function () { Route::group(['prefix' => '/v1', 'middleware' => ['laniakea.version:v1']], function () { Route::post('/products', [ProductsApiController::class, 'store']); }); Route::group(['prefix' => '/v2', 'middleware' => ['laniakea.version:v2']], function () { Route::post('/products', [ProductsApiController::class, 'store']); }); }); ``` -------------------------------- ### Override Full Translation Path for Exceptions (PHP) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/exceptions.md This code example shows how to completely override the translation path for a specific exception by implementing the `getTranslationPath()` method. This provides full control over where the translation strings are located. It depends on the `LaniakeaExceptionsBaseHttpException` class. ```php where('uuid', $this->id); } } ``` -------------------------------- ### Access Original Query Builder (PHP) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/repositories.md Explains how to access the underlying Eloquent query builder instance using the `getQueryBuilder()` method. This allows you to use any methods available on `IlluminateDatabaseEloquentBuilder` for more advanced query customization. ```php $users = $usersRepository->list(function (RepositoryQueryBuilderInterface $query) { $queryBuilder = $query->getQueryBuilder(); // Call original query builder's methods. $queryBuilder->with(['posts.comments'])->take(10)->skip(15); }); ``` -------------------------------- ### Example Translation File Structure (PHP Array) Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/exceptions.md This PHP array defines a translation structure that supports nested error codes, allowing for variations like 'users.not_found.message' and 'users.not_found.email.message'. This structure is used in conjunction with exception handling to provide specific error messages. ```php [ 'not_found' => [ 'message' => 'Пользователь с ID :user_id не найден.', 'email' => ['message' => 'Пользователь с таким email не найден.'], ], ], ]; ``` -------------------------------- ### Loading Relationships Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/resources/manager.md Load related resources using the `with` query parameter. Nested relationships can also be loaded. ```APIDOC ## GET /users?with=[relationships] ### Description Retrieves a list of users and includes specified related resources. ### Method GET ### Endpoint /users ### Query Parameters - **with** (string) - Optional - Comma-separated list of relationships to load. Can include nested relationships (e.g., `posts.comments`). ### Request Example ``` GET /users?with=posts,avatar GET /users?with=posts.comments ``` ### Response #### Success Response (200) - **data** (array) - An array of user objects, potentially with included relationships. #### Response Example ```json { "data": [ { "id": 1, "name": "John Doe", "email": "john.doe@example.com", "posts": [ { "id": 101, "title": "First Post" } ], "avatar": { "url": "/path/to/avatar.jpg" } } ] } ``` ``` -------------------------------- ### Products API Controller - Index Method - PHP Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/resources/versions.md Demonstrates the index method of the ProductsApiController, which utilizes Laniakea's ResourceManagerInterface to paginate and retrieve product resources. It takes resource manager and resource interfaces as dependencies and returns a JSON response. ```php paginate($request, $resource, new ProductsRepository()); return response()->json($paginator); } } ``` -------------------------------- ### Set Default Settings for Custom Field in PHP Source: https://github.com/tzurbaev/laniakea-docs/blob/main/docs/forms/fields/custom.md This example shows how to set default settings for a custom Laniakea form field. By overriding the getDefaultSettings() method, you can provide an array of default configurations. Field-specific methods, like setFormat(), can be added to allow overriding these defaults. ```php 'hex', ]; } /** * This method will override the default `format` setting. */ public function setFormat(string $format): static { return $this->setSetting('format', $format); } } ```