PHP code example of vursion / laravel-sitemappable
1. Go to this page and download the library: Download vursion/laravel-sitemappable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
return [
/*
* This is the name of the table that will be created by the migration and
* used by the Sitemappable model shipped with this package.
*/
'db_table_name' => 'sitemap',
/*
* The generated XML sitemap is cached to speed up performance.
*/
'cache' => '60 minutes',
/*
* The batch import will loop through this directory and search for models
* that use the IsSitemappable trait.
*/
'model_directory' => 'app/Models',
/*
* If you're extending the controller, you'll need to specify the new location here.
*/
'controller' => Vursion\LaravelSitemappable\Http\Controllers\SitemappableController::class,
];
use Illuminate\Database\Eloquent\Model;
use Vursion\LaravelSitemappable\IsSitemappable;
class YourModel extends Model
{
use IsSitemappable;
public function toSitemappableArray()
{
return [];
}
public function shouldBeSitemappable()
{
return true;
}
}
public function toSitemappableArray()
{
return [
'nl' => 'https://www.vursion.io/nl/testen/test-slug-in-het-nederlands',
'en' => 'https://www.vursion.io/en/tests/test-slug-in-english',
];
}
public function toSitemappableArray()
{
return collect(localization()->getSupportedLocalesKeys())->mapWithKeys(function ($key) {
return [$key => localization()->getUrlFromRouteName($key, 'routes.your-route-name', ['slug' => $this->getTranslationWithoutFallback('slug', $key)])];
});
}
public function shouldBeSitemappable()
{
return (! $this->draft && $this->published);
}
return [
...
/*
* If you're extending the controller, you'll need to specify the new location here.
*/
'controller' => App\Http\Controllers\SitemappableController::class,
...
];
public function otherRoutes()
{
return [
[
'nl' => 'https://www.vursion.io/nl/contacteer-ons',
'en' => 'https://www.vursion.io/en/contact-us',
],
...
];
}