xml sitemap in laravel 8 |
How to Generate and Read Sitemap XML File in Laravel 8
Laravelium Sitemap generator for Laravel.
Notes
- Dev Branches are for development and are UNSTABLE (use on your own risk)!
Installation
Run the following command and provide the latest stable version (e.g v8.*) :
composer require laravelium/sitemap
or add the following to your composer.json
file :
For Laravel 8
"laravelium/sitemap": "8.*"
(development branch)
"laravelium/sitemap": "8.x-dev"
For Laravel 7
"laravelium/sitemap": "7.*"
(development branch)
"laravelium/sitemap": "7.x-dev"
For Laravel 6
"laravelium/sitemap": "6.*"
(development branch)
"laravelium/sitemap": "6.x-dev"
For Laravel 5.8
"laravelium/sitemap": "3.1.*"
(development branch)
"laravelium/sitemap": "3.1.x-dev"
For Laravel 5.7
"laravelium/sitemap": "3.0.*"
(development branch)
"laravelium/sitemap": "3.0.x-dev"
For Laravel 5.6
"laravelium/sitemap": "2.8.*"
(development branch)
"laravelium/sitemap": "2.8.x-dev"
For Laravel 5.5
"laravelium/sitemap": "2.7.*"
(development branch)
"laravelium/sitemap": "2.7.x-dev"
Publish needed assets (styles, views, config files) :
php artisan vendor:publish --provider="Laravelium\Sitemap\SitemapServiceProvider"
Note: Composer won't update them after composer update
, you'll need to do it manually!
$site = App::make('sitemap');
$site->add(URL::to('/'), date("Y-m-d h:i:s"), 1, 'daily');
$Allpost = postModel::where('Type','=','Post')->orderBy('id', 'DESC')->get();
$CategorData = subcategoryCategoryModel::orderBy('id', 'DESC')->get();
foreach ($Allpost as $item => $value){
$site->add(URL::to($value->permalink), $value->created_at, 1, 'daily');
}
foreach ($CategorData as $item => $value){
$site->add(URL::to('/categories/'.$value->CategoryName), $value->created_at, 1, 'daily');
}
$site->store('xml', 'sitemap');
Source: https://github.com/Laravelium/laravel-sitemap
إرسال تعليق