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
[9.x] Precognition #8261
base: 9.x
Are you sure you want to change the base?
[9.x] Precognition #8261
Conversation
<a name="executing-controller"></a> | ||
### Executing Code In A Controller | ||
|
||
As previously discussed, Laravel Precognition with not invoke the controller, however many applications may not be using route model binding, form requests, and middleware and instead are doing this work in the controller. This is why we have created a mechanism for applications that want to use Precognition but also keep their code co-located within the controller. Imagine we have the following controller: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As previously discussed, Laravel Precognition with not invoke the controller, however many applications may not be using route model binding, form requests, and middleware and instead are doing this work in the controller. This is why we have created a mechanism for applications that want to use Precognition but also keep their code co-located within the controller. Imagine we have the following controller: | |
As previously discussed, Laravel Precognition will not invoke the controller, however many applications may not be using route model binding, form requests, and middleware and instead are doing this work in the controller. This is why we have created a mechanism for applications that want to use Precognition but also keep their code co-located within the controller. Imagine we have the following controller: |
@timacdonald This looks awesome! We hope to adopt this as soon as possible! Any plans to when to release the npm packages - or if you would make the repositories public while they're getting worked on? |
I would also love to try it, I have been following the PR's since Laracon |
<a name="handling-precognitive-requests"></a> | ||
### Handling Precognitive Requests | ||
|
||
Precognitive requests should generally be side-effect free. This is where the Precognition "pattern" comes in. It is recommend when you add Precognition to your routes that you consider the side-effects triggered in your application's middleware and form requests. If the side-effects present should be skipped for precognitive requests, you may need to add a conditional around the side-effect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precognitive requests should generally be side-effect free. This is where the Precognition "pattern" comes in. It is recommend when you add Precognition to your routes that you consider the side-effects triggered in your application's middleware and form requests. If the side-effects present should be skipped for precognitive requests, you may need to add a conditional around the side-effect. | |
Precognitive requests should generally be side-effect free. This is where the Precognition "pattern" comes in. It is recommended when you add Precognition to your routes that you consider the side-effects triggered in your application's middleware and form requests. If the side-effects present should be skipped for precognitive requests, you may need to add a conditional around the side-effect. |
</template> | ||
``` | ||
|
||
We will enhance this implementation by adding live validation powered by Laravel Precognition. To achieve this we will create a precognitive form, passing through the method, url, and initial form data. Then we will: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will enhance this implementation by adding live validation powered by Laravel Precognition. To achieve this we will create a precognitive form, passing through the method, url, and initial form data. Then we will: | |
We will enhance this implementation by adding live validation powered by Laravel Precognition. To achieve this, we will create a precognitive form, passing through the method, url, and initial form data. Then we will: |
|
||
- Precognition requests MUST have a `Precognition` header with the value `true`. | ||
- Precognition responses MUST have a `Precognition` header with the value `true`. | ||
- When requesting specific inputs be validated, the `Precognition-Validate-Only` header SHOULD be used. The value MUST be a comma seperated list in input names e.g. `email,phone,address`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- When requesting specific inputs be validated, the `Precognition-Validate-Only` header SHOULD be used. The value MUST be a comma seperated list in input names e.g. `email,phone,address`. | |
- When requesting specific inputs be validated, the `Precognition-Validate-Only` header SHOULD be used. The value MUST be a comma separated list in input names e.g. `email,phone,address`. |
}); | ||
``` | ||
|
||
To disable this feature you may specify a fingerprint of `null`. You may disable it globally by passing `null` to `fingerprintRequestsUsing`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To disable this feature you may specify a fingerprint of `null`. You may disable it globally by passing `null` to `fingerprintRequestsUsing`: | |
To disable this feature, you may specify a fingerprint of `null`. You may disable it globally by passing `null` to `fingerprintRequestsUsing`: |
<a name="installation"></a> | ||
## Installation | ||
|
||
The frontend helper libraries make working with Precognition a dreamy delight. If you are going to use Precognition, we recommend installing the appropriate library for your project. There is a vanilla JavaScript and Vue flavoured package available via NPM: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The frontend helper libraries make working with Precognition a dreamy delight. If you are going to use Precognition, we recommend installing the appropriate library for your project. There is a vanilla JavaScript and Vue flavoured package available via NPM: | |
The frontend helper libraries make working with Precognition a dreamy delight. If you are going to use Precognition, we recommend installing the appropriate library for your project. There is a vanilla JavaScript and Vue flavored package available via NPM: |
<a name="configuration"></a> | ||
### Configuration | ||
|
||
The Precognition configuration object is the [Axios' configuration](https://axios-http.com/docs/req_config) object with some additional options to customize behaviour and also make handling common responses easier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Precognition configuration object is the [Axios' configuration](https://axios-http.com/docs/req_config) object with some additional options to customize behaviour and also make handling common responses easier. | |
The Precognition configuration object is the [Axios' configuration](https://axios-http.com/docs/req_config) object with some additional options to customize behavior and also make handling common responses easier. |
<a name="validating-vue-inertia"></a> | ||
### Working With Vue and Inertia | ||
|
||
Inertia has a built-in form helper that makes working with forms a lovely experience. We wanted to maintain this experience while enabling realtime validation with Precognition, so we decided to wrap Inertia's form helper. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any plans to support React too?
Hello,
this package is not found |
See: laravel/framework#44339