-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
add custom type hint #2
Conversation
Hi @MarceloSantosCorrea , I also have a suggestion about that: if ($typeHint !== null && class_exists($typeHint)) {
if (!in_array($typeHint, ['int', 'float', 'string', 'bool']) && !in_array($typeHint, $patterns)
&& !is_subclass_of($typeHint, 'Illuminate\Database\Eloquent\Model')) {
continue;
}
} What do you think about that? |
I thought about that too, but I wanted to make it broader in case you want to inject other types of classes, by injecting Laravel's dependencies. |
When do we use other types of classes for the Route params? As far as I know, for the Route params can be Model or primitives types like int, string, etc. What could we use else? |
Laravel, here is an example. Another example that can be passed are Interfaces that can be solved with Binding |
I know that, but question is can we use Route param binding for all classes/interfaces types? According to documentation of the Laravel Routing, we can solve Model binding because Routing package supports that. But I couldn't find anything else for specific class binding in Router. You can check this documentation. Could you please share any example for any other class like Service, Library, Helper for solving Route param binding? I'm trying to sure about that. |
'can we use route parameter binding for all types of classes/interfaces?', yes, I already made use of it, in the example I used was to implement the Socialite package, where I pass the network name by string parameter and in the controller it is returned to provider instance. in routes/web.php
in controller
in App\Providers\AppServiceProvider
|
Okay, I understand clearly. So, we can merge the your PR! Thank you so much again! |
If there is another way, I apologize for this PR, but this contribution is to be able to add Model as type hint:
file
auto-route.php
in controller