Skip to content

Commit

Permalink
better route mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
inerba committed Dec 1, 2023
1 parent c6ea156 commit 8e01cc2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ return [
* to specify them, it is for obtaining a more user-friendly table.
*/
'mappings' => [
'App\Models\Miogest\Property' => [
'type' => 'Immobile',
'pluralType' => 'Immobili',
'label' => 'ID: {id}',
'urlPrefix' => 'property',
'titleField' => 'titolo',
'slugField' => 'slug',
],
// EXAMPLE:
// 'App\Models\Property' => [
// 'type' => 'Property',
// 'pluralType' => 'Properties',
// 'label' => 'ID: {id}',
// 'titleField' => 'name',
// 'route' => 'property',
// 'record_identifier' => 'slug',
// ],
],
];
```
Expand Down Expand Up @@ -140,10 +141,6 @@ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed re

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

## Security Vulnerabilities

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

## Credits

- [Francesco Apruzzese](https://github.com/inerba)
Expand Down
17 changes: 9 additions & 8 deletions config/contact-logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
* to specify them, it is for obtaining a more user-friendly table.
*/
'mappings' => [
'App\Models\Miogest\Property' => [
'type' => 'Immobile',
'pluralType' => 'Immobili',
'label' => 'ID: {id}',
'urlPrefix' => 'property',
'titleField' => 'titolo',
'slugField' => 'slug',
],
// EXAMPLE:
// 'App\Models\Property' => [
// 'type' => 'Property',
// 'pluralType' => 'Properties',
// 'label' => 'ID: {id}',
// 'titleField' => 'name',
// 'route' => 'property',
// 'record_identifier' => 'slug',
// ],
],
];
8 changes: 4 additions & 4 deletions src/Resources/ContactLogResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public static function table(Table $table): Table
})
->url(function ($record) {
// Ottieni la configurazione con un valore di default
$urlPrefix = config("contact-logs.mappings.{$record->contactable_type}.urlPrefix");
$slugField = config("contact-logs.mappings.{$record->contactable_type}.slugField");
$route = config("contact-logs.mappings.{$record->contactable_type}.route");
$record_identifier = config("contact-logs.mappings.{$record->contactable_type}.record_identifier");

if ($urlPrefix && $slugField && $record->contactable) {
return route($urlPrefix, $record->contactable->{$slugField});
if ($route && $record_identifier && $record->contactable) {
return route($route, $record->contactable->{$record_identifier});
}

return false;
Expand Down

0 comments on commit 8e01cc2

Please sign in to comment.