Skip to content

v13 docs #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 91 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
06074cc
docs(wip): add v13 upgrade guide first draft
Mohammad-Alavi Mar 30, 2025
58cd1ce
Update upgrade-guide.md
Mohammad-Alavi Mar 30, 2025
2a4f2c0
docs: laravel passport
Mohammad-Alavi Mar 30, 2025
2b7f674
Update upgrade-guide.md
Mohammad-Alavi Mar 30, 2025
a4d4606
docs: value objects
Mohammad-Alavi Mar 30, 2025
f72bec5
docs: value objects
Mohammad-Alavi Mar 30, 2025
6ca0005
docs: request
Mohammad-Alavi Mar 30, 2025
a9ffd9a
docs: exceptions
Mohammad-Alavi Mar 30, 2025
2b4e294
docs: response
Mohammad-Alavi Apr 4, 2025
9c799e4
docs: repository
Mohammad-Alavi Apr 4, 2025
465b04c
docs: hash ids
Mohammad-Alavi Apr 4, 2025
c4fc5d9
docs: jobs
Mohammad-Alavi Apr 4, 2025
8bb931d
docs: jobs
Mohammad-Alavi Apr 4, 2025
bb8e093
docs: validation
Mohammad-Alavi Apr 4, 2025
7ee2900
Update upgrade-guide.md
Mohammad-Alavi Apr 4, 2025
c2e04e5
docs: testing
Mohammad-Alavi Apr 4, 2025
ba714ba
Update upgrade-guide.md
Mohammad-Alavi Apr 4, 2025
14a4443
Update upgrade-guide.md
Mohammad-Alavi Apr 4, 2025
e7d6f1d
Update upgrade-guide.md
Mohammad-Alavi Apr 4, 2025
47d17cd
Update package-lock.json
Mohammad-Alavi Apr 5, 2025
ca0d49e
refactor: change file extension
Mohammad-Alavi Apr 5, 2025
d5535b1
docs: composer dependencies
Mohammad-Alavi Apr 5, 2025
8cf77b0
Update upgrade-guide.mdx
Mohammad-Alavi Apr 5, 2025
b8435fb
Update upgrade-guide.mdx
Mohammad-Alavi Apr 5, 2025
cea723b
Update upgrade-guide.mdx
Mohammad-Alavi Apr 5, 2025
5fa1c00
Update upgrade-guide.mdx
Mohammad-Alavi Apr 5, 2025
dc287c5
Update upgrade-guide.mdx
Mohammad-Alavi Apr 6, 2025
7cdd338
Update upgrade-guide.mdx
Mohammad-Alavi Apr 7, 2025
0d1aabe
docs: upgrade utils
Mohammad-Alavi Apr 7, 2025
806b7b3
style: remove empty line
Mohammad-Alavi Apr 7, 2025
dc39b14
Update upgrade-guide.mdx
Mohammad-Alavi Apr 7, 2025
1b2713c
Update upgrade-guide.mdx
Mohammad-Alavi Apr 11, 2025
2e8e166
Update release-notes.md
Mohammad-Alavi Apr 11, 2025
ba8de42
docs: code gen command change
Mohammad-Alavi Apr 11, 2025
7078d4c
Create advance-configuration.mdx
Mohammad-Alavi Apr 11, 2025
e639e3c
docs: routing configuration
Mohammad-Alavi Apr 11, 2025
51e1ec8
Update release-notes.md
Mohammad-Alavi Apr 11, 2025
75a8def
Update routes.md
Mohammad-Alavi Apr 12, 2025
a4f48ea
Update advance-configuration.mdx
Mohammad-Alavi Apr 12, 2025
80de19e
Update routes.md
Mohammad-Alavi Apr 12, 2025
ea78567
Update registration.mdx
Mohammad-Alavi Apr 12, 2025
0f85e99
Update localization.md
Mohammad-Alavi Apr 12, 2025
ad8a024
Update transformers.md
Mohammad-Alavi Apr 12, 2025
2b00b9d
Update controllers.md
Mohammad-Alavi Apr 12, 2025
ac16c19
Update requests.md
Mohammad-Alavi Apr 12, 2025
4716049
Update requests.md
Mohammad-Alavi Apr 12, 2025
6803a01
Update models.md
Mohammad-Alavi Apr 12, 2025
9157147
Update routes.md
Mohammad-Alavi Apr 12, 2025
a9f4d12
Update views.md
Mohammad-Alavi Apr 12, 2025
be9e51d
Update advance-configuration.mdx
Mohammad-Alavi Apr 12, 2025
a3cf549
Update exceptions.md
Mohammad-Alavi Apr 12, 2025
0c22d47
Update models.md
Mohammad-Alavi Apr 12, 2025
f9e178f
Update views.md
Mohammad-Alavi Apr 12, 2025
19e2000
Update commands.md
Mohammad-Alavi Apr 12, 2025
605b5d2
Update events.md
Mohammad-Alavi Apr 12, 2025
02562cd
Update factories.md
Mohammad-Alavi Apr 12, 2025
62d2cad
Update mail.md
Mohammad-Alavi Apr 12, 2025
a80c3be
Update advance-configuration.mdx
Mohammad-Alavi Apr 12, 2025
5d61282
Update advance-configuration.mdx
Mohammad-Alavi Apr 12, 2025
50f9e13
Update routes.md
Mohammad-Alavi Apr 12, 2025
5fbb6ef
Update views.md
Mohammad-Alavi Apr 12, 2025
b991723
Update configs.md
Mohammad-Alavi Apr 12, 2025
bb54b9c
Update factories.md
Mohammad-Alavi Apr 12, 2025
82a5f80
Update middlewares.md
Mohammad-Alavi Apr 12, 2025
5c90cea
Update notifications.md
Mohammad-Alavi Apr 12, 2025
2ec7e80
Update policies.md
Mohammad-Alavi Apr 12, 2025
6833985
Update seeders.md
Mohammad-Alavi Apr 12, 2025
10cb360
Update service-providers.md
Mohammad-Alavi Apr 12, 2025
f584622
Update social-authentication.md
Mohammad-Alavi Apr 12, 2025
e53002c
Update exceptions.md
Mohammad-Alavi Apr 12, 2025
7f48f1f
Update service-providers.md
Mohammad-Alavi Apr 12, 2025
51cbf8b
Update tests.md
Mohammad-Alavi Apr 12, 2025
65f2bf4
Update values.md
Mohammad-Alavi Apr 12, 2025
bb5e802
Update upgrade-guide.mdx
Mohammad-Alavi Apr 12, 2025
fa4a4c0
Update authentication.mdx
Mohammad-Alavi Apr 12, 2025
d1805c9
Update authorization.mdx
Mohammad-Alavi Apr 12, 2025
fee2070
Update advance-configuration.mdx
Mohammad-Alavi Apr 14, 2025
5f8940d
Update api-versioning.md
Mohammad-Alavi Apr 14, 2025
1307819
Update code-generator.md
Mohammad-Alavi Apr 14, 2025
a31ee59
Update etag.md
Mohammad-Alavi Apr 14, 2025
eeca78f
Update rate-limiting.md
Mohammad-Alavi Apr 14, 2025
c30a578
Update rbac.md
Mohammad-Alavi Apr 14, 2025
180f2ed
Update email-varification.md
Mohammad-Alavi Apr 14, 2025
be77a2d
Update hash-id.md
Mohammad-Alavi Apr 14, 2025
4ff68ba
Update password-reset.md
Mohammad-Alavi Apr 14, 2025
dd42c59
Delete profiler.md
Mohammad-Alavi Apr 14, 2025
3d9b743
Create apps.md
Mohammad-Alavi Apr 14, 2025
f0ea906
Create helpers.md
Mohammad-Alavi Apr 14, 2025
734a335
docs: create new category
Mohammad-Alavi Apr 14, 2025
df404d9
Delete localization.md
Mohammad-Alavi Apr 14, 2025
29ca72e
Delete social-authentication.md
Mohammad-Alavi Apr 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/architecture-concepts/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ In summary, a Container represents a cohesive set of related functionalities.
It can be a specific feature or a wrapper around a RESTful API resource.

To generate new containers along with all their [components](components.md),
you may use the `apiato:generate:container` interactive command:
you may use the `apiato:make:container` interactive command:

```
php artisan apiato:generate:container
php artisan apiato:make:container
```

## Composer Dependencies
Expand All @@ -48,8 +48,8 @@ The choice of location depends on what is most relevant and convenient for your

Each Container has the option to include a `readme.md` file at its root, which serves to explain the Container's purpose and how to use it.

To generate new readme files, you may use the `apiato:generate:readme` interactive command:
To generate new readme files, you may use the `apiato:make:readme` interactive command:

```
php artisan apiato:generate:readme
php artisan apiato:make:readme
```
4 changes: 2 additions & 2 deletions docs/components/main-components/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ tags:
Actions serve as the embodiment of the application's Use Cases,
encapsulating the various operations that users or software can execute within the application.

To generate new actions you may use the `apiato:generate:action` interactive command:
To generate new actions you may use the `apiato:make:action` interactive command:

```shell
php artisan apiato:generate:action
php artisan apiato:make:action
```

Additionally, to retrieve a list of the existing actions in your Apiato application,
Expand Down
116 changes: 15 additions & 101 deletions docs/components/main-components/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ tags:
serving the requested data and constructing the corresponding response.

To generate new controllers
you may use the `apiato:generate:controller` interactive command:
you may use the `apiato:make:controller` interactive command:

```
php artisan apiato:generate:controller
php artisan apiato:make:controller
```

## Definition & Principles
Expand All @@ -37,7 +37,6 @@ Read [**Porto SAP Documentation (#Controllers)**](https://github.com/Mahmoudz/Po
- MUST extend the `App\Ship\Parents\Controllers\WebController` class.
- Controllers:
- MUST only call the `run` or `transactionalRun` method of Actions.
- SHOULD pass the Request object to the Action instead of passing data from the request.

## Folder Structure

Expand Down Expand Up @@ -96,113 +95,28 @@ class Controller extends WebController
}
```

:::tip
In case you want to handle the same Action differently based on the UI type (e.g., API, Web, CLI), you can set the
UI on Action with `setUI` method.
## Response

```php
$action = app(Action::class);
$action->setUI('web');
```
You can use the `Apiato\Support\Facades\Response` facade to create a new response object.

and get the UI in your Action with `getUI` method.
The `Response` class extends `Spatie\Fractal\Fractal` to enhance its functionality for API responses.
It adds methods for resource key management, meta information, and standardized HTTP responses.

```php
$action->getUI(); // will return 'web'
```
:::info Further Reading
For more detailed information,
please refer to [Fractal](https://fractal.thephpleague.com/transformers/) and [Laravel Fractal Wrapper](https://github.com/spatie/laravel-fractal) documentations.
:::

## Response Helpers Methods

### transform
This method is incredibly useful and will be used in most cases.
Here are some examples of how to use the `Response` facade:

- The first required parameter accepts data as an object or a Collection of objects.
- The second required parameter is the transformer class.
- The third optional parameter allows you to specify the [includes](transformers.md#including-relationships) that should be returned in the response.
- The fourth optional parameter lets you include metadata in the response. This metadata will be returned under the `meta` key in the `custom` key.

```php
// With Includes
$this->transform($resource, ResourceTransformer::class, ['foo', 'bar']);
```
```php
// With Meta
$this->transform($resource, ResourceTransformer::class, meta: ['foo' => 'bar', 'baz' => 1]);
Response::create($user)->transformWith(UserTransformer::class)->json(null, 200);

// Response
{
"data": {},
"meta": {
"include": [...],
"custom": {
"foo": "bar",
"baz": 1
},
"pagination": {}
}
}
```
### withMeta
This method enables you to add metadata to the response,
and it MUST be used in conjunction with the `transform` method.
This is different from the `meta` parameter in the `transform` method.
This metadata will be returned directly under the `meta` key.

You can use this method in conjunction with the `meta` parameter in the `transform` method.

```php
$metaData = ['foo' => 999, 'bar'];
Response::create()->transformWith(UserTransformer::class)->ok($user);

$this->withMeta($metaData)->transform($sample, SampleTransformer::class, meta: ['foo' => 'bar', 'baz' => 1]);
Response::create($user, UserTransformer::class)->created();

// Response
{
"data": {},
"meta": {
"foo": 999,
"0": "bar",
"include": [...],
"custom": {
"foo": "bar",
"baz": 1
},
"pagination": {}
}
}
```
Response::create($user, UserTransformer::class)->parseIncludes(['permissions'])->toArray();

### json
This method allows you to pass an array of data that will be represented as JSON.
```php
$this->json($data)
```

### created
This method allows you to return a response with a `201` status code.
```php
$this->created($data)
```

### deleted
This method allows you to return a response with a `202` status code.
```php
$this->deleted($deletedModel)

// Response
{
"message": "Model (1) Deleted Successfully."
}
```

### accepted
This method allows you to return a response with a `202` status code.
```php
$this->accepted($data)
```

### noContent
This method allows you to return a response with a `204` status code.
```php
$this->noContent()
Response::ok();
```
64 changes: 6 additions & 58 deletions docs/components/main-components/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ tags:

Exceptions are used to handle errors and exceptions in the application.

To generate new exceptions you may use the `apiato:generate:exception` interactive command:
To generate new exceptions, you may use the `apiato:make:exception` interactive command:

```
php artisan apiato:generate:exception
php artisan apiato:make:exception
```

## Definition & Principles
Expand All @@ -23,9 +23,10 @@ Read [**Porto SAP Documentation (#Exceptions)**](https://github.com/Mahmoudz/Por

- All container-specific Exceptions MUST be placed in the `app/Containers/{Section}/{Container}/Exceptions` directory.
- All general Exceptions MUST be placed in the `app/Ship/Exceptions` directory.
- All Exceptions MUST extend the `App\Ship\Parents\Exceptions\Exception` class.
- All application Exceptions MUST extend the `App\Ship\Parents\Exceptions\Exception` class.
- The parent extension SHOULD be aliased as `ParentException`.
- Every Exception MUST have at least two properties: `code` and `message`.
- All Http Exceptions MUST extend the `App\Ship\Parents\Exceptions\HttpException` class.
- The parent extension SHOULD be aliased as `ParentHttpException`.

## Folder Structure

Expand All @@ -47,57 +48,4 @@ app

## Code Example

You can override those values while throwing the error.

```php
use App\Ship\Parents\Exceptions\Exception as ParentException;

class DemoException extends ParentException
{
protected $code = Response::HTTP_CONFLICT;
protected $message = 'This is a demo exception.';
}
```

## Helpers Methods

### withErrors

```php
// Example 1
throw (new AccountFailedException())->withErrors(['email' => 'The email has already been taken.']);
// Example 2
throw (new AccountFailedException())->withErrors(['email' => ['The email has already been taken.', 'Another message']]);
```

You can also use translation strings.
Translation strings are automatically translated if the translations are found.
To handle localization, you can use the [Localization Container](../../pacakges/localization.md).

```php
// Example 1
throw (new AccountFailedException())->withErrors(['email' => 'appSection@user::exceptions.email-taken']);
// Example 2
throw (new AccountFailedException())->withErrors(['email' => 'appSection@user::exceptions.email-taken', 'Another not translated message']);
```

Response:
```json
{
"message": "The exception error message.",
"errors": {
"email": [
"The email has already been taken.",
"Another not translated message"
]
}
}
```
### debug

The `debug` method is used for logging error messages during debugging and development.
The `debug` method accepts `string` or `\Exception` instance

```php
throw (new AccountFailedException())->debug($e);
```
Exceptions are defined exactly as you would define them in Laravel.
17 changes: 9 additions & 8 deletions docs/components/main-components/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ and providing an abstraction for interacting with that data.
They encapsulate the business logic and rules associated with the data,
as well as facilitate the communication with the underlying database.

To generate new models you may use the `apiato:generate:model` interactive command:
To generate new models you may use the `apiato:make:model` interactive command:

```
php artisan apiato:generate:model
php artisan apiato:make:model
```

## Definition & Principles
Expand Down Expand Up @@ -48,19 +48,20 @@ app

Models are defined exactly as you would define them in Laravel.

## Model Trait
## Custom Models {#custom-models}

If your model does not extend the `App\Ship\Parents\Models\Model` or the `App\Ship\Parents\Models\UserModel` class,
it is essential to incorporate the `ModelTrait` trait into your model.
it is essential to implement the `ResourceKeyAware` interface
and use the `InteractsWithApiato` trait in your model.
By doing so, your model will benefit from various functionalities provided by the trait,
such as hash ids and other features necessary for proper integration with the framework.

```php
use Apiato\Core\Traits\ModelTrait;
use Apiato\Core\Models\InteractsWithApiato;
use Apiato\Http\Resources\ResourceKeyAware;

class Demo
class Demo implements ResourceKeyAware
{
use ModelTrait;
...
use InteractsWithApiato;
}
```
Loading
Loading