增加网站地图
This commit is contained in:
62
app/Http/Controllers/SitemapController.php
Normal file
62
app/Http/Controllers/SitemapController.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
use App\Models\Staff;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class SitemapController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('category.sitemap');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 保存
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2022/6/30 14:29
|
||||
* @return mixed
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$url = [
|
||||
url('/'),
|
||||
url('staff'),
|
||||
];
|
||||
|
||||
$sitemap = App::make("sitemap");// 创建一个生成站点地图的对象
|
||||
|
||||
$sitemap->setCache('laravel.sitemap', 3600);// 设置缓存
|
||||
|
||||
$categories = Category::where('status', 1)->get();
|
||||
foreach ($categories as $category) {
|
||||
$url[] = $category->link;
|
||||
}
|
||||
|
||||
$articles = Article::shown()->get();
|
||||
foreach ($articles as $article) {
|
||||
$url[] = $article->link;
|
||||
}
|
||||
|
||||
|
||||
$staffs = Staff::shown()->get();
|
||||
foreach ($staffs as $staff) {
|
||||
$url[] = $staff->link;
|
||||
}
|
||||
|
||||
|
||||
$dateTime = date('Y-m-d H:i:s');
|
||||
foreach ($url as $k => $v) {
|
||||
$sitemap->add($v, $dateTime, '1.0', 'daily');
|
||||
}
|
||||
|
||||
// 渲染站点地图(options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf')
|
||||
return $sitemap->store('xml');
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
"fideloper/proxy": "^4.0",
|
||||
"laravel-admin-ext/config": "^1.1",
|
||||
"laravel/framework": "^7.0",
|
||||
"laravelium/sitemap": "^7.0",
|
||||
"laravel/tinker": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
|
||||
3473
composer.lock
generated
3473
composer.lock
generated
File diff suppressed because it is too large
Load Diff
29
resources/views/category/sitemap.blade.php
Normal file
29
resources/views/category/sitemap.blade.php
Normal file
@@ -0,0 +1,29 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('content')
|
||||
<!-- Start 内容区域 -->
|
||||
<div class="second">
|
||||
<div class="container">
|
||||
<div class="secondCont">
|
||||
<!-- 导航 -->
|
||||
@if($all_categorys->isNotEmpty())
|
||||
@foreach($all_categorys as $category)
|
||||
@if($category->children->isNotEmpty())
|
||||
<div class="itemize">
|
||||
<div class="itemize-title">{{ $category->title }}</div>
|
||||
<ul class="itemize-ul">
|
||||
@foreach($category->children()->where('status',1)->get() as $child)
|
||||
<li>
|
||||
<a href="{{ $child->link }}">{{ $child->title }}</a>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@endforeach
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -21,6 +21,9 @@ Route::get('category/{category}', 'CategoryController@show')->name('category.sho
|
||||
Route::resource('leader', 'LeaderController');
|
||||
Route::resource('staff', 'StaffController');
|
||||
|
||||
Route::get('sitemap', 'SitemapController@index');
|
||||
Route::get('sitemapstore', 'SitemapController@store');
|
||||
|
||||
//以下为导入数据
|
||||
Route::get('test/set_article_category', 'TestController@set_article_category');
|
||||
Route::get('test/set_category', 'TestController@set_category');
|
||||
|
||||
Reference in New Issue
Block a user