robsontenorio / mary

Laravel Blade UI Components for Livewire 3
https://mary-ui.com
Other
804 stars 88 forks source link

Named route in table link property #471

Closed bucari closed 2 weeks ago

bucari commented 3 weeks ago

Hi @robsontenorio

i have a table component where i would like to use a named route in the link property, but the {id} is not accessible

@php              
    $headers = [
        ['key' => 'id', 'label' => 'Doc. Id'],
        ['key' => 'user.name', 'label' => 'User'],
        ['key' => 'state', 'label' => 'State'],  
        ['key' => 'created_at', 'label' => 'Created at'] 
    ];
@endphp                
<x-mary-table :headers="$headers" :rows="$this->vpns()" :sort-by="$sortBy" 
    wire:model="selected" selectable with-pagination
    link="{{route('doc-review', ['docType' => 'vpn', 'id' => '{id}'])}}"    
>

</x-mary-table>
robsontenorio commented 3 weeks ago

What plain text url it outputs ? For yours {{ route(xxx) }}

bucari commented 3 weeks ago

Url like this https://hostname/doc/vpn/review/1

robsontenorio commented 3 weeks ago

What final html/table/tr/td/a code it renders for your link attribute?

image

bucari commented 3 weeks ago

Nothing, it gives me an error

Missing required parameter for [Route: doc-review] [URI: doc/{docType}/review/{id}] [Missing parameter: id].

robsontenorio commented 3 weeks ago

But this error comes from Laravel itself if you try to print that route, not specifically for table component.

bucari commented 3 weeks ago

No this error occurs because {id} token is not evaluated inside this {{route(...)}}, it works olny if i use a string in link parameter

robsontenorio commented 3 weeks ago

There is no other way to handle this, as you are trying to use “route()” method.

For now, please use it as string. As advised on docs https://mary-ui.com/docs/components/table#click-to-navigate