robsontenorio / mary

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

Table link / route suggestion #578

Closed flatcapco closed 2 months ago

flatcapco commented 2 months ago

When defining a table link we use a string that gets extracted and pulls the variables from each row which is really nice.

However once the size of the project grows it starts becoming hard to maintain that the string is still valid without writing tests for the links. My suggestion is that link gets extended to allow passing a route() so that named routes can be used. maybe instead of using link we use :route instead? :route="route('office.discount-codes',$id)" I'm happy to try and work on this if you think its a good idea or something you'd merge?
robsontenorio commented 2 months ago

I can’t think an easy way to implement it, but if you got , I would accept it. 👍

flatcapco commented 2 months ago

Ok i'm not sure if this is mental or not... but if we use the route helper to start the process we could handle it with something similar to generate the string that we pass to the table.. this means that phpstorm or other ides would still recognise the route() input which i think solves the issue.


$client_id = 0;
$contact_id = 0;

$fullUrl = route("office.clients.contacts.edit", [
  "client" => $client_id,
  "contact" => $contact_id
]);

$relativeUrl = str_replace(url("/"), "", $fullUrl);

// Replace the parameters in sequence, ensuring the client_id and contact_id are replaced correctly
$relativeUrl = preg_replace(
  "/\b" . $client_id . "\b/",
  "{client_id}",
  $relativeUrl,
  1
);
$relativeUrl = preg_replace(
  "/\b" . $contact_id . "\b/",
  "{contact_id}",
  $relativeUrl,
  1
);

$relativeUrl outputs /office/clients/{client_id}/contacts/{contact_id}

So we can then pass that to the table.

OR if we pass in something like :route="route("office.clients.contacts.edit", [ "client" => 0, "contact" => 0 ])"

we can then do the relative processing within the table like you do with the rows?

robsontenorio commented 2 months ago

Could you give a try on this PR #595 Please, let me know if it is ok.

flatcapco commented 2 months ago

@robsontenorio perfect Rob thanks so much