Replies: 2 comments 7 replies
-
sorry... the formatting got removed... here it is with formatting Hi, we are trying to assign models to the url defaults, the same way you can pass a model as parameter to the route function. What we try to achieve
However we found out that the url defaults are just assigned as is, in this case we get the JSON string of the event model. Example:
What we found as possible fix (but not sure if this causes any other trouble), if we adapt line Illuminating\Routing\UrlGenerator.php:494
we get as expected result Kind regards, Andries |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if the quite generic |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
we are trying to assign models to the url defaults, the same way you can pass a model as parameter to the route function.
However we discovered this is not working.
What we try to achieve
//$event is an instance of App\Models\Event::class.
URL::defaults([
'event' => $event,
]);
However we found out that the url defaults are just assigned as is, in this case we get the JSON string of the event model.
Example:
Route::get('/events/{event:slug}/orders/{order:uuid}',[OrderController::class,'show'])->name('event.order.show');
route('event.order.show',['order' => $order ]);
->result 'events/{"id":1,"name":"eventname", "slug":"event-slug"}/orders/8f07a5bf-d517-4e2e-8f8e-c5d6eac18d46'
What we found as possible fix (but not sure if this causes any other trouble), if we adapt line Illuminating\Routing\UrlGenerator.php:494
$parameters = collect(Arr::wrap($parameters))->map(function ($value, $key) use ($route) {
to
$parameters = collect(array_merge($this->getDefaultParameters(),Arr::wrap($parameters)))->map(function ($value, $key) use ($route) {
we get as expected result
'events/event-slug/orders/8f07a5bf-d517-4e2e-8f8e-c5d6eac18d46'
is this a missing feature / bug on Laravel's side, or are we abusing the URL::defaults feature?
Kind regards,
Andries
Beta Was this translation helpful? Give feedback.
All reactions