Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make it possible to receive parameters directly in the method:
For example, let's take the following simple procedure, where we pass two values for which we want to get the subtract:
In this case, we need to write something like the following in the handler:
It is rather strange when we operate with a small number of parameters and without specifying their type. So let us make it possible to pass these arguments on-demand automatically. That could be written as follows:
It will also work for deep things, via
camelCase
:for argument:
Specifying the same names when working with code and documentation
We can use different variable names in the code and expected
JSON
parameters in the proposed implementation. However, this can lead to confusion over time. For example, one command is called$user_id
, and the other$client_id
. It seems like an absolutely odd thing that hurts rather than adds value.Binding declaration
I think we should rely on how laravel does it. Take our substract example:
This will automatically replace the substituted value in our method:
But at the same time, the request will contain the original value that was passed.
As for the binding to the models, here I am on the side of the sequence, as I mentioned earlier. However, it is extraordinary that the API would accept different values for the same value in other places. For example, the
$user
parameter in one place was defined byid
, in another byemail
.Therefore, you should rely on what is indicated in the model. By default, it looks like this. (Every
Eloquent
model has this)If this needs to be changed, and accept more email or something else. You can change this condition by adding
->orWhere
. This will be consistent, since in all procedures, the user will be the same, and not depend on how the FormRequest is written:And this is how we declare the model binding in a straightforward way:
It will work for anyone where the
$user
argument is expected, and this value is passed.As with automatic substitution, bindings
RPC::bind
andRPC::model
can be set for nested elements. To do this, you need to use thedot
notation in the declaration. For example:In turn, this will expect
camelCase
in the arguments: