Download the PHP package vursion/laravel-sitemappable without Composer
On this page you can find all versions of the php package vursion/laravel-sitemappable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vursion/laravel-sitemappable
More information about vursion/laravel-sitemappable
Files in vursion/laravel-sitemappable
Package laravel-sitemappable
Short Description laravel-sitemappable
License MIT
Homepage https://github.com/vursion/laravel-sitemappable
Informations about the package laravel-sitemappable
Laravel Sitemappable
Installation
You can install the package via composer:
No need to register the service provider if you're using Laravel >= 5.5.
The package will automatically register itself.
Once the package is installed, you can register the service provider in config/app.php
in the providers array:
You need to publish the migration with:
You should publish the config/sitemappable.php
config file with:
This is the content of the published config file:
Making a model sitemappable
The required steps to make a model sitemappable are:
- Add the
Vursion\LaravelSitemappable\IsSitemappable
trait. - Define a public method
toSitemappableArray
that returns an array with the (localized) URL(s). - Optionally define the conditions when a model should be sitemappable in a public method
shouldBeSitemappable
.
Here's an example of a model:
toSitemappableArray
You need to return an array with (localized) URL(s) of your model.
This is an example of a model that uses ARCANDEDEV\Localization for localized routes in combination with spatie\laravel-translatable for making Eloquent models translatable.
shouldBeSitemappable (conditionally sitemappable model instances)
Sometimes you may need to only make a model sitemappable under certain conditions.
For example, imagine you have a App\Models\Posts\Post
model.
You may only want to allow "non-draft" and "published" posts to be sitemappable.
To accomplish this, you may define a shouldBeSitemappable
method on your model:
Rebuild the sitemap from scratch
If you are installing Laravel Sitemappable into an existing project, you may already have database records you need to import into your sitemap.
Laravel Sitemappable provides a sitemappable:import
Artisan command that you may use to import all of your existing records into your sitemap:
Adding non-model associated routes
It's very likely your project will have routes that are not associated with a model.
You can add these URLs by extending the controller and returning them via the otherRoutes
method.
To publish the controller to app/Http/Controllers/SitemappableController.php
run:
Don't forget to change the location of the controller in the config/sitemappable.php
config file:
Just make sure you return an array of arrays with key/value pairs like the example below:
Changelog
Please see CHANGELOG for more information what has changed recently.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.