Skip to content

Commit 4ae846e

Browse files
docs: add getSlug() method and usage examples to API documentation
- Added getSlug() method to API table with parameter descriptions - Added "Getting Model URLs" section with practical code examples - Documented how to use relative_url, absolute_url attributes - Showed examples of getSlug() with different parameters Closes #5 Co-authored-by: Vladislav Stoitsov <[email protected]>
1 parent 3632034 commit 4ae846e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class LivewireComponentExample extends Component
169169
| **Methods** | Description | Parameters |
170170
|-----------------------------------|------------------------------------------------------------- |-------------------- |
171171
| generateUrl() | Generate manually the URL | |
172+
| getSlug() | Get the URL for a specific language in relative or absolute format | ?string $language = '', bool $relative = true |
172173
| urlStrategy | The strategy for creating the URL for the model | $language, $locale |
173174
| isAutoGenerateUrls() | Disable generating urls on creation, globally for the model | |
174175
| disableGeneratingUrlsOnCreate() | Disable generating urls on creation | |
@@ -178,6 +179,25 @@ class LivewireComponentExample extends Component
178179
| **Relations** | | |
179180
| urls() | All the active urls, related to the current model | |
180181

182+
### Getting Model URLs
183+
184+
```php
185+
// Get relative URL for current locale
186+
$model->relative_url; // e.g., "my-product-name"
187+
188+
// Get absolute URL for current locale
189+
$model->absolute_url; // e.g., "https://example.com/my-product-name"
190+
191+
// Get URL for specific language (relative)
192+
$model->getSlug('en', true); // e.g., "my-product-name"
193+
194+
// Get URL for specific language (absolute)
195+
$model->getSlug('en', false); // e.g., "https://example.com/my-product-name"
196+
197+
// Get URL for current locale (defaults to app locale)
198+
$model->getSlug(); // e.g., "my-product-name"
199+
```
200+
181201
## Commands
182202
### urls:generate
183203
This command generates unique URLs for the specified model or all models in the application that implement the `HasUniqueUrls` trait.

0 commit comments

Comments
 (0)