Closed netzknecht closed 8 months ago
Hi @netzknecht,
First, it's not "vanilophp" framework; it's called "Vanilo". "vanilophp" is just the GitHub handle since "vanilo" was taken.
Second, Vanilo is not manipulating that part in any way, but I may help figure out the root cause. Questions:
Having the answers for this might help to figure it out.
Hi @fulopattila122,
sorry for choosing the wrong term and many thanks for the effort for this project. I've also noticed, that the issue is related to route model binding generally, no matter if implicit or explicit, so I'll change the title of this topic.
It affects only Vanilo models with SoftDeletes-trait.
No, I've tested it without a controller and without Vanilo Admin installed.
You should reproduce it with a soft deleted user model and the following route:
Route::get('user/{user}', function(\Konekt\User\Models\User $user) {
dd($user);
})->withTrashed();
In addition:
It doesn't matter if the model \Konekt\User\Models\User
or the contract \Konekt\User\Contracts\User
is type-hinted.
Tested in a fresh Laravel 10.10 "sails" environment + Sanctum 3.2 + Telescope 4.15 + Vanilo 3.1.
Got it, thanks for the investigation. I'll take a look next week. I suspect it could be related to Concord's model features.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed within 3 days if no further activity occurs. Thank you for your contributions.
Closing because of being stalled for 3 days without activity.
I think I've found something: If you rename the parameter to, e.g., $uzer,
then it works. Otherwise, it doesn't work - exactly as you described.
The route cause is the usage of Laravel's explicit Route binding:
App\Models\User
:
Route::get('user/{uzer}', function(\App\Models\User $uzer) {
dd($uzer);
})->withTrashed();
config/concord.php
file
<?php
return [ 'register_route_models' => false, 'modules' => [ //... ] ];
2. When registering your own model, make sure to pass `false` as the third parameter (prevents explicit route model binding)
```php
// app/Providers/AppServiceProvider.php
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
$this->app->concord->registerModel(\Konekt\User\Contracts\User::class, \App\Models\User::class, false);
}
}
This way, the route you posted will properly use the trashing mechanism without renaming the user
parameter:
Hello,
when playing around with vanilophp framework, I've noticed that the withTrashed()-method for implicit model binding isn't working with vanilophp, like described in laravel doc's in chapter "Routing, Soft Deleted Models". Query logging still show's "[..] and
users
.deleted_at
is null limit 1" for the query fired for implicit model binding, even the "withTrashed()"-method is given. It seems to me, that the "resolveSoftDeletableRouteBinding"-method isn't called if vanilophp framework is active, instead the "resolveRouteBinding"-method is called always.Because I can't find the exact reason why and running out of time, I helped me out with customizing the resolution logic resolveRouteBinding()-method and use it in a trait for relevant routes eg. models for now.