Skip to content

Commit

Permalink
Update docs (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-thomas committed Dec 6, 2023
1 parent 6009bf7 commit d88fa83
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 55 deletions.
32 changes: 15 additions & 17 deletions docs/content/docs/Basics/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ title: "Helpers"
weight: 2
---

## Traits

### EnumHelper
## EnumHelper

this trait brings useful static methods to enum classes.

Expand Down Expand Up @@ -51,39 +49,39 @@ this trait brings useful static methods to enum classes.

{{< /column >}}

#### toArray
##### toArray

Convert values of an enum class to an array.

#### toArrayKeys
##### toArrayKeys

Convert keys of an enum class to an array.

#### toArrayExcept
##### toArrayExcept

Convert values of an enum class to an array except the given values.

#### toArrayKeysExcept
##### toArrayKeysExcept

Convert keys of an enum class to an array except the given keys.

#### toArrayOnly
##### toArrayOnly

Convert given values of an enum class to an array.

#### toArrayKeysOnly
##### toArrayKeysOnly

Convert given keys of an enum class to an array.

#### all
##### all

Create an array using all enum members.

#### IndexedAll
##### IndexedAll

Create an array using values of all enum members.

#### tryFromKey
##### tryFromKey

Find a value using the given key, otherwise return the default value.

Expand Down Expand Up @@ -117,22 +115,22 @@ Valravn includes several global functions that you can use in your code.

{{< /column >}}

#### user
##### user

Return authenticated user or optional null.

#### resolveRelatedIdToModel
##### resolveRelatedIdToModel

Resolve the given id to a related model.

#### resolveMorphableToResource
##### resolveMorphableToResource

Resolve given Model to a resource class.

#### logg
##### logg

Log the given exception to a specific channel and format.

#### slugify
##### slugify

Make a english or non-english string to a slug.
8 changes: 4 additions & 4 deletions docs/content/docs/Basics/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ string.
domain/api/blog/categories?per_page=5
```

## Available methods
#### Available methods

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

Expand All @@ -52,7 +52,7 @@ domain/api/blog/categories?per_page=5

{{< /column >}}

#### aliasForModelAttributes
##### aliasForModelAttributes

This method is useful when you want to define an alias for an attribute or a
foreign key of a model. its usage should be something like this:
Expand Down Expand Up @@ -89,7 +89,7 @@ class Comment extends ValravnModel {
And the `itsPostId` attribute method helps us get the related value using the
same way of a real attribute.

#### table
##### table

It's a shorthand for getting table name of a model class.

Expand All @@ -99,7 +99,7 @@ Example::table()
( new Example )->getTable();
```

#### foreignKey
##### foreignKey

It's a shorthand for getting foreign key of a model class.

Expand Down
26 changes: 13 additions & 13 deletions docs/content/docs/Basics/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weight: 2
There is a repository base class that contains CRUD and other useful method
which you can use to avoid redundancy.

### Available methods
#### Available methods

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

Expand Down Expand Up @@ -61,26 +61,26 @@ which you can use to avoid redundancy.

{{< /column >}}

#### getQueryBuilder
##### getQueryBuilder

After creating your repository class by your self our using
valravn `repository` [command](commands.md#repository), you must implement this
method to establish related query builder object for repository class.

#### disableAuthorization
##### disableAuthorization

Every actions on builder instance should authorize. sometimes you don't want to
authorize your query, so by calling `disableAuthorization` method on your
repository instance, the repository doesn't authorize the action.

#### enableAuthorization
##### enableAuthorization

Sometimes you want to run an action without authorization but after that in the
same scope, you want to run an action with authorization. in this scenario, you
need to call `disableAuthorization` method first and after that
call `enableAuthorization` method to enable authorization again.

#### query
##### query

When you call an action like `all`, you might don't want all columns of rows. so
you can use `select` method before `all` and pass your specific columns to
Expand All @@ -92,7 +92,7 @@ instance.
Notice: it's recommended to get builder instance using `query` method instead of `getQueryBuilder`.
{{< /tip >}}

#### authorize
##### authorize

Using this method you will be able to authorize actions. there is some examples.

Expand Down Expand Up @@ -144,7 +144,7 @@ public function viewComments( Post $model ): Builder {
}
```

#### authorizeThisAction
##### authorizeThisAction

It's just a shorthand for `authorize` method.

Expand All @@ -154,11 +154,11 @@ $this->authorizeThisAction( $param );
$this->authorize( null, $param );
```

#### all
##### all

Return query builder instance and ables us to access the all rows.

#### find
##### find

Find a specific resource using `id` by default. but if you want to find a row by
another column, you just need to do something like this:
Expand All @@ -170,20 +170,20 @@ app( SampleRepository::class )->find('specific-slug-for-example','slug');
First parameter is the value and the second value is the column name that
Valravn should search in.

#### create
##### create

Create a resource using given data and return the created model as result.

#### update
##### update

Update specific Model using given data and return a boolean as result.

#### batchUpdate
##### batchUpdate

Update many resources in one query at once and also return a bool value as
result.

#### delete
##### delete

Delete a specific resource and return `true`. otherwise throw an
exception. `delete` method contains two `deleting` and `deleted` hook.
20 changes: 9 additions & 11 deletions docs/content/docs/Basics/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ classes but there are more features! </br>
You can create resource classes on your own or just using our
[resources command](commands.md#resources).

### ValravnJsonResource
## ValravnJsonResource

it's same as `JsonResource` class on laravel. to start using this, first you
need to create resource class which should see something like this.
Expand Down Expand Up @@ -37,7 +37,7 @@ You can specify the model's attributes in `extract` method that you wand to see
in response. the `type` method determines related entity on this response for
the front-end dev.

### ValravnResourceCollection
## ValravnResourceCollection

The resource collection class is the same as `ValravnJsonResource`.

Expand All @@ -58,7 +58,7 @@ class SampleCollection extends ValravnResourceCollection {
}
```

## Available methods
#### Available methods

Resource classes contain several methods and in continue, we will introduce them.

Expand Down Expand Up @@ -359,7 +359,7 @@ SampleResource::make($model)->withExampleInclude();
let's talk about how The front-end dev should work with defined includes. let's
assume we just want to include a relationship. all we need to do is this:

```
```plain
domain/api/namespace/name?includes=example
```

Expand All @@ -372,7 +372,7 @@ To eager load a relationship, you must pass the registered include using `includ
Valravn allows you to use nested eager loads. for that you just need to pass the
nested includes after the first one and split them using a `.` character.

```
```plain
domain/api/namespace/name?includes=example.owner
```

Expand Down Expand Up @@ -411,7 +411,7 @@ Columns you pass as parameter to actions, must be in filterable list of related
This action allows you just fetch columns that you want. it might help create
optimized requests.

```
```plain
domain/api/blog/posts?includes=comments:select(content).user:select(first_name|last_name)
```

Expand All @@ -425,7 +425,7 @@ doesn't resolve by ORM.

The `order` action ables you to set order for your relationship results.

```
```plain
domain/api/blog/posts?includes=comments:select(content):order(created_at)
```

Expand All @@ -434,15 +434,15 @@ domain/api/blog/posts?includes=comments:select(content):order(created_at)
Using this action, you can limit the number of rows must fetch from related
relationship.

```
```plain
domain/api/blog/categories?includes=posts:limit(5)
```

this request will return the categories while each category loaded with at least
5 related posts. however the `limit` action accepts two parameter. the second
parameter acts like page number.

```
```plain
domain/api/blog/categories?includes=posts:limit(5|2)
```

Expand Down Expand Up @@ -496,5 +496,3 @@ PostResource::make( $this->post )
]
)
```


10 changes: 5 additions & 5 deletions docs/content/docs/Basics/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ weight: 2

Valravn has several services that each one has their own functionality.

### Service contract
## Service contract

Service classes must extend `Hans\Valravn\Services\Contracts\Service` class.

Expand Down Expand Up @@ -40,7 +40,7 @@ Sometimes you need to conditionally determine you want to use cache or not.
app( ExampleService::class )->cacheWhen( user()->isNotAdmin() )->calculatePopularExamples();
```

### Caching logic
## 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 Down Expand Up @@ -70,7 +70,7 @@ use Hans\Valravn\Facades\Cache;
Cache::store( 'unique_key', fn() => 10 / 12 );
```

### Notifiable
## Notifiable

This contract let you have a notification for each action depending on model.
the notification contains a title, body and a related model.
Expand All @@ -79,7 +79,7 @@ the notification contains a title, body and a related model.
Notifications will not store in database.
{{< /tip >}}

### FilteringService
## FilteringService

The `FilteringService` allows us to apply some logics on query builder instance
through api calls.
Expand Down Expand Up @@ -226,7 +226,7 @@ domain/api/blog/posts/1/comments?or_where_relation_filter[comments->title]=somet
It's the same as `or_where_relation_filter` but this filter add a where like
condition instead of where.

### RoutingService
## RoutingService

This service helps you to define your routes. the `Hans\Valravn\Facades\Router`
facade is here to make it easy to use this service.
Expand Down
4 changes: 2 additions & 2 deletions docs/content/docs/Basics/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ weight: 2

For testing, there is some helpful methods that can be found so handy.

### Available methods
#### Available methods

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

Expand Down Expand Up @@ -71,7 +71,7 @@ public function example(): void {
}
```

### Factory contract
## Factory contract

This contract helps to create fake data for your test suite. the implementation class should be like this.

Expand Down
2 changes: 1 addition & 1 deletion docs/themes/compose/assets/js/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const snippet_actions = [
show: true
},
{
icon: 'order',
icon: 'toggle-line-numbers',
id: 'lines',
title: toggle_line_numbers_text,
show: true
Expand Down
2 changes: 1 addition & 1 deletion docs/themes/compose/layouts/partials/sprites.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<path d="m496 512.007812h-138.667969c-8.832031 0-16-7.167968-16-16 0-8.832031 7.167969-16 16-16h122.667969v-122.667968c0-8.832032 7.167969-16 16-16s16 7.167968 16 16v138.667968c0 8.832032-7.167969 16-16 16zm0 0"></path>
<path d="m496 512.007812c-4.097656 0-8.191406-1.558593-11.308594-4.691406l-181.332031-181.335937c-6.25-6.25-6.25-16.382813 0-22.632813s16.382813-6.25 22.636719 0l181.332031 181.332032c6.25 6.25 6.25 16.382812 0 22.636718-3.136719 3.132813-7.230469 4.691406-11.328125 4.691406zm0 0"></path>
</symbol>
<symbol enable-background="new 0 0 512 512" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" id="order">
<symbol enable-background="new 0 0 512 512" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" id="toggle-line-numbers">
<path d="m492 236h-347.738c-11.046 0-20 8.954-20 20s8.954 20 20 20h347.738c11.046 0 20-8.954 20-20s-8.954-20-20-20z"></path>
<path d="m492 86h-347.738c-11.046 0-20 8.954-20 20s8.954 20 20 20h347.738c11.046 0 20-8.954 20-20s-8.954-20-20-20z"></path>
<path d="m492 386h-347.738c-11.046 0-20 8.954-20 20s8.954 20 20 20h347.738c11.046 0 20-8.954 20-20s-8.954-20-20-20z"></path>
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Relation extends Command
*
* @var string
*/
protected $description = 'Generate store and update request classes.';
protected $description = 'Generate store and update request classes for a specific relationship.';

private Filesystem $fs;

Expand Down

0 comments on commit d88fa83

Please sign in to comment.