Skip to content

Commit

Permalink
docs updated;
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-thomas committed Jun 13, 2023
1 parent 74bedcc commit 30bce2e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 42 deletions.
5 changes: 3 additions & 2 deletions docs/content/docs/Basics/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ app/

This command generates repository and repository contract.

> Reminder: bind the contract to the repository class in
> RepositoryServiceProvider
{{< tip >}}
Reminder: bind the contract to the repository class in RepositoryServiceProvider
{{< /tip >}}

```bash
valravn:policy namespace name
Expand Down
5 changes: 3 additions & 2 deletions docs/content/docs/Basics/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ValravnErrorCode extends ErrorCode {

}
```
{{< tip >}}
If you are defining an ErrorCode as a method, don't forget to prefix the number.
{{< /tip >}}

> If you are defining an ErrorCode as a method, don't forget to prefix the
> number.
8 changes: 6 additions & 2 deletions docs/content/docs/Basics/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ public function getFilterableAttributes(): array {

As you can see, you can set alias for a column.

> Notice: some features depend on implementing this contract.
{{< tip >}}
Notice: some features depend on implementing this contract.
{{< /tip >}}

##### Loadable

Expand All @@ -185,7 +187,9 @@ public function getLoadableRelations(): array {
}
```

> Notice: there is some dependency of implementing this contract.
{{< tip >}}
Notice: there is some dependency of implementing this contract.
{{< /tip >}}

##### ResourceCollectionable

Expand Down
5 changes: 3 additions & 2 deletions docs/content/docs/Basics/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ fetch. there can be more methods like `select`. the important point here is,
methods like `select` only apply when you use `query` method to get builder
instance.

> Notice: it's recommended to get builder instance using `query` method instead
> of `getQueryBuilder`.
{{< tip >}}
Notice: it's recommended to get builder instance using `query` method instead of `getQueryBuilder`.
{{< /tip >}}

#### authorize

Expand Down
48 changes: 29 additions & 19 deletions docs/content/docs/Basics/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,13 @@ class FirstExampleQuery extends ResourceQuery {
in `apply` method, you should return an array. we merge the data into the
related resource instance using the array key that you defined.

> Make sure there is not any conflict with extracted attributes of the related
> resource.
{{< tip >}}
Make sure there is not any conflict with extracted attributes of the related resource.
{{< /tip >}}

> this data will merge into the `data` key on response.
{{< tip >}}
this data will merge into the `data` key on response.
{{< /tip >}}

### Collection Query

Expand Down Expand Up @@ -152,9 +155,9 @@ class RelatedExamplesCollectionQuery extends CollectionQuery {
}
}
```

> It's recommended that suffix the class with `CollectionQuery` to avoid any
> conflict and mistake.
{{< tip >}}
It's recommended that suffix the class with `CollectionQuery` to avoid any conflict and mistake.
{{< /tip >}}

### Queries registration

Expand All @@ -178,7 +181,9 @@ public function getAvailableQueries(): array {
the array's key is the query string that a front-end dev can trigger this query
and the value must be the query class.

> It's recommended to prefix query strings with `with_` to avoid any conflict.
{{< tip >}}
It's recommended to prefix query strings with `with_` to avoid any conflict.
{{< /tip >}}

### Parse queries

Expand Down Expand Up @@ -246,8 +251,9 @@ class ExampleIncludes extends Includes {
}
```

> It's recommended to create includes in a sub folder where the related resource
> classes are locate.
{{< tip >}}
It's recommended to create includes in a sub folder where the related resource classes are locate.
{{< /tip >}}

### Includes registration

Expand Down Expand Up @@ -310,8 +316,9 @@ assume we just want to include a relationship. all we need to do is this:
domain/api/namespace/name?includes=example
```

> Notice: to eager load a relationship, you must pass the registered include
> using `includes` key.
{{< tip >}}
To eager load a relationship, you must pass the registered include using `includes` key.
{{< /tip >}}

#### Nested eager loads

Expand All @@ -321,18 +328,19 @@ nested includes after the first one and split them using a `.` character.
```
domain/api/namespace/name?includes=example.owner
```

> Notice: We consider the ExampleResource class registered `owner` include.
> otherwise this will not work.
{{< tip >}}
We consider the ExampleResource class registered `owner` include. otherwise this will not work.
{{< /tip >}}

#### Actions

There are some default actions that you can use on your api calls. you are free
to use an action for two relationship or different actions for any includes.
actions must split using `:` character.

> Notice: columns you pass as parameter to actions, must be in filterable list
> of related model.
{{< tip >}}
columns you pass as parameter to actions, must be in filterable list of related model.
{{< /tip >}}

{{< column "methods-container" >}}

Expand All @@ -359,9 +367,11 @@ optimized requests.
domain/api/blog/posts?includes=comments:select(content).user:select(first_name|last_name)
```

> Notice: if there is a belongs to relationship, and you want to use `select`
> action, don't forget to select the foreign key too. otherwise the relationship
> doesn't resolve by ORM.
{{< tip >}}
If there is a belongs to relationship, and you want to use `select`
action, don't forget to select the foreign key too. otherwise the relationship
doesn't resolve by ORM.
{{< /tip >}}

##### order

Expand Down
49 changes: 36 additions & 13 deletions docs/content/docs/Basics/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@ Sometimes you need to conditionally determine you want to use cache or not.
app( ExampleService::class )->cacheWhen( user()->isNotAdmin() )->calculatePopularExamples();
```

### Notifiable

This contract let you have a notification for each action depending on model.
the notification contains a title, body and a related model.

> Notice: notifications will not store in database.

### CachingService
### Caching logic

This service helps up caching data and retrieve them on next calls. the logic of
this service is a bit complicated but in the simplest way, it caches data and
Expand All @@ -59,15 +52,41 @@ the data will retrieve from cache. after :15 o'clock requests should receive
fresh data for the first time. and cached data in second 15m will be valid
until :29 o'clock.

> Notice: you can set you custom interval by using `setInterval` method.
#### CachingService

You can set your custom interval by using `setInterval` method.

```php
app( PostRelationsService::class )->cache()->setInterval( 20 )->viewCategories();
```

#### Cache facade

This facade let you cache some data using same [logic](#caching-logic).

```php
use Hans\Valravn\Facades\Cache;
Cache::store( 'unique_key', fn() => 10 / 12 );
```

### Notifiable

This contract let you have a notification for each action depending on model.
the notification contains a title, body and a related model.

{{< tip >}}
Notifications will not store in database.
{{< /tip >}}

### FilteringService

The `FilteringService` allows us to apply some logics on query builder instance
through api calls.

> Notice: only [filterable columns](models.md#filterable) can be use in
> filtering requests.
{{< tip >}}
Only [filterable columns](models.md#filterable) can be use in filtering requests.
{{< /tip >}}

To apply requested filters on your queries, you should call `applyFilters` method on your query builder instance. it's
recommended to call `applyFilters` in your service layer.
Expand Down Expand Up @@ -179,7 +198,9 @@ This filter ables you to fetch posts that has a command with a specific title.
domain/api/blog/posts/1/comments?where_relation_filter[comments->title]=something
```

> Notice: only [loadable relations](models.md#loadable) is valid.
{{< tip >}}
Only [loadable relations](models.md#loadable) is valid.
{{< /tip >}}

##### where_relation_like_filter

Expand Down Expand Up @@ -391,7 +412,9 @@ If you want to access gathering routes using route's name, you can
use `{name}.gathering.{action_name}-v{version}` pattern. for example the first
gathering route's name is `posts.gathering.posts-v1`.

> Notice: the gathering data just depend on you page sections.
{{< tip >}}
The gathering data just depend on you page sections.
{{< /tip >}}

There is an example of implementing a method on gathering controller. you can
use `AnonymousResourceCollection` and pass your resource or resource collection
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Target":"css/styles.5d0a4ae1a1a0bd6808a09c2e7ec6ad502caab08117245477e128717a069090988127bb54fa6b0798b81c6dd006749de668708684f0d1ebf49222d78cb9e6da19.css","MediaType":"text/css","Data":{"Integrity":"sha512-XQpK4aGgvWgIoJwufsatUCyqsIEXJFR34ShxegaQkJiBJ7tU+msHmLgcbdAGdJ3maHCGhPDR6/SSIteMuebaGQ=="}}
{"Target":"css/styles.c6a4d7b163cf8442a77dd63bbdfffce9dbb728a60418905d4c47120aaa6a95364fee48d2f4e8fbabd5d556b37df6f58e1506ff083567931be360275e9180a9d2.css","MediaType":"text/css","Data":{"Integrity":"sha512-xqTXsWPPhEKnfdY7vf/86du3KKYEGJBdTEcSCqpqlTZP7kjS9Oj7q9XVVrN99vWOFQb/CDVnkxvjYCdekYCp0g=="}}

1 comment on commit 30bce2e

@vercel
Copy link

@vercel vercel bot commented on 30bce2e Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

valravn – ./

valravn-git-master-hans-thomas.vercel.app
valravn.vercel.app
valravn-hans-thomas.vercel.app

Please sign in to comment.