This commit is contained in:
2020-09-16 08:37:18 +08:00
parent fd2e97e190
commit ea72828001
13 changed files with 1289 additions and 136 deletions

View File

@@ -20,7 +20,7 @@ class IndexController extends AdminController
*/
protected function grid()
{
return Grid::make(new Advert(['category']), function (Grid $grid) {
return Grid::make(Advert::with(['category']), function (Grid $grid) {
$grid->column('id')->sortable();
$grid->column('cover', '图片')->image('', 60, 60);
$grid->column('category.title', '分类名称');

View File

@@ -20,7 +20,7 @@ class IndexController extends AdminController
*/
protected function grid()
{
return Grid::make(new Article(['category']), function (Grid $grid) {
return Grid::make(Article::with(['category']), function (Grid $grid) {
$grid->column('id', '#ID#');
$grid->column('cover', '封面图片')->image('', 60, 60);

View File

@@ -21,7 +21,7 @@ class IndexController extends AdminController
{
return Grid::make(new Link(), function (Grid $grid) {
$grid->column('id')->sortable();
$grid->column('title');
$grid->column('title', '标题');
$grid->column('url');
$grid->column('created_at');
$grid->column('updated_at')->sortable();

View File

@@ -9,42 +9,16 @@ use Illuminate\Http\Request;
class ArticleController extends Controller
{
//文章列表
public function index(Category $category)
{
$articles = Article::where('category_id', $category->id)
->orderBy('created_at', 'desc')
->paginate(5);
return view('articles.index', compact('articles', 'category'));
}
//显示详情
public function show(Article $article)
{
if ($article->url) {
return redirect($article->url);
}
$category = $article->category;
$parent = $category->getTop();
$next = Article::where('id', '>', $article->id)->where('status', 1)->first();
return view('articles.show', compact('article', 'category', 'next'));
}
//搜索
public function search(Request $request)
{
$title = $request->title;
$articles = Article::where('status', 1)
->when($title, function ($q) use ($title) {
$q->where('title', 'like', "%{$title}%");
})
->paginate();
return view('articles.search', compact('articles'));
return view('articles.show', compact('article', 'category', 'parent'));
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Http\Controllers;
use App\Models\Article;
use App\Models\Category;
class CategoryController extends Controller
{
//显示分类
public function show(Category $category)
{
if ($category->type == Category::TYPE_SHOW) {
if ($category->relations) {
return redirect(route('article.show', $category->relations));
}
return redirect('/');
}
$articles = Article::where('category_id', $category->id)
->latest('sort')
->latest()
->paginate();
$parent = $category->getTop();
return view('category.show', compact('category', 'parent', 'articles'));
}
}

View File

@@ -57,4 +57,16 @@ class Category extends Model
return $this->hasMany(__CLASS__, 'parent_id');
}
//查找顶级分类
public function getTop()
{
$parent = $this;
while ($parent->parent_id != 0) {
$parent = $parent->parent;
}
return $parent;
}
}

1110
new_caauto.sql Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,49 +0,0 @@
@extends('layouts.app')
@section('title', '')
@section('keywords', $category->keywords)
@section('description', $category->description)
@section('css')
<style type="text/css">
.noImg .newsl{
display: none;
}
.noImg .newsr{
width: 100% !important;
}
</style>
@endsection
@section('content')
<div class="mabody">
<div class="mainWarp">
@include('layouts.left')
<div class="mainRight">
<div class="brandnavbox">
<p class="ccsl">{{ $category->title }}</p>
<div class="con ccsl">首页 > {{ $category->title }} ></div>
</div>
<ul class="listul">
@foreach($articles as $article)
<li @if(empty($article->cover)) class="noImg" @endif>
<div class="newsl">
<a href="{{ route('article.show', $article) }}"><img src="{{ \Storage::disk('public')->url($article->cover) }}" /></a>
</div>
<div class="newsr">
<a href="{{ route('article.show', $article) }}" class="ccsl">{{ $article->title }}</a>
<hr>
<div class="sub">{{ $article->description }}</div>
{{-- <a href="{{ route('article.show', $article) }}" class="more">查看更多>> </a> --}}
<span style="margin-top: 10px;display: block; color: #999; font-size: 14px;">{{ $article->created_at }}</span>
</div>
</li>
@endforeach
</ul>
<div class="clear"></div>
{{ $articles->links() }}
</div>
<div class="clear"></div>
</div>
</div>
<div class="clear"></div>
@endsection

View File

@@ -1,38 +0,0 @@
@extends('layouts.app')
@section('title', '搜索结果')
@section('content')
<!-- content -->
<div class="container mian">
<div class="mian-content-header">
<a href="#">首页</a>
<i class="fa fa-caret-right"></i>
<a href="#">搜索结果</a>
</div>
<!-- 文章列表 -->
<ul class="results-news-ul">
@if ($articles->isNotEmpty())
@foreach ($articles as $article)
<li>
<a class="nowrap" href="{{ $article->link }}">
<i class="fa fa-angle-double-right"></i>
{{ $article->title }}
<span>{{ $article->created_at->format('Y-m-d') }}</span>
</a>
</li>
@endforeach
@endif
</ul>
<!-- 分页 -->
<div class="pages">
@if ($articles->isNotEmpty())
{{ $articles->links('layouts.pagination') }}
@endif
</div>
</div>
<!-- end content -->
@endsection

View File

@@ -4,23 +4,46 @@
@section('content')
<!-- content -->
<div class="container details">
<!-- 文章标题 -->
<h3 class="details-title">{{ $article->title }}</h3>
<p class="details-time">{{ $article->created_at }}</p>
<!-- 文章详情 -->
<div class="details-content">
<!-- 详情 -->
<div class="details">
<div class="contant">
<div class="page-left">
<div class="pagelist">
<h1>{{ $parent->title }}</h1>
<ul class="listbox">
@if ($parent->children->isNotEmpty())
@foreach ($parent->children as $children)
<li @if($category->id==$children->id) class="active" @endif>
<a href="{{ $children->link }}">{{ $children->title }}</a>
</li>
@endforeach
@endif
</ul>
</div>
</div>
<div class="page-right">
<div class="pagelujing">
<div class="name">{{ $category->title }}</div>
<span>
您当前所在位置:<a href="/">首页</a> &gt;
@if ($category->id!=$parent->id)
<a href="{{ $parent->link }}">{{ $parent->title }}</a> &gt;
@endif
<a href="{{ $category->link }}">{{ $category->title }}</a>
</span>
</div>
<div class="news-txt ny mg-t-b">
<div class="biaoti">{{ $article->title }}</div>
<div class="sshuomign"><span>发布时间:{{ $article->created_at->format('Y-m-d') }}</span></div>
<div class="article_txt">
@if ($article->cover)
<img src="{{ $article->cover_path }}">
@endif
{!! $article->content !!}
</div>
<!-- 下一篇 -->
@if ($next)
<div class="details-writings">
<a href="{{ $next->link }}">下一篇:{{ $next->title }}</a>
</div>
@endif
</div>
</div>
</div>
<!-- end 详情 -->
@endsection

View File

@@ -0,0 +1,56 @@
@extends('layouts.app')
@section('title', $category->title)
@section('content')
<!-- 详情 -->
<div class="details">
<div class="contant">
<div class="page-left">
<div class="pagelist">
<h1>{{ $parent->title }}</h1>
<ul class="listbox">
@if ($parent->children->isNotEmpty())
@foreach ($parent->children as $children)
<li @if($category->id==$children->id) class="active" @endif>
<a href="{{ $children->link }}">{{ $children->title }}</a>
</li>
@endforeach
@endif
</ul>
</div>
</div>
<div class="page-right">
<div class="pagelujing">
<div class="name">{{ $category->title }}</div>
<span>
您当前所在位置:<a href="/">首页</a> &gt;
@if ($category->id!=$parent->id)
<a href="{{ $parent->link }}">{{ $parent->title }}</a> &gt;
@endif
<a href="{{ $category->link }}">{{ $category->title }}</a>
</span>
</div>
<div class="news-txt ny mg-t-b">
<div class="news-con">
<ul class="newslist ny">
@if ($articles->isNotEmpty())
@foreach ($articles as $article)
<li>
<a href="{{ $article->link }}">{{ $article->title }}</a><span>{{ $article->created_at->format('m-d') }}</span>
</li>
@endforeach
@endif
</ul>
<div class="tcdPageCode">
@if ($articles->isNotEmpty())
{{ $articles->links('layouts.pagination') }}
@endif
</div>
</div>
</div>
</div>
</div>
</div>
<!-- end 详情 -->
@endsection

View File

@@ -0,0 +1,32 @@
@if ($paginator->hasPages())
<div class="pages">
{{-- Previous Page Link --}}
@if ($paginator->onFirstPage())
<span class="disabled">上一页</span>
@else
<a href="{{ $paginator->previousPageUrl() }}">上一页</a>
@endif
{{-- Pagination Elements --}}
@foreach ($elements as $element)
{{-- Array Of Links --}}
@if (is_array($element))
@foreach ($element as $page => $url)
@if ($page == $paginator->currentPage())
<span class="current">{{ $page }}</span>
@else
<a href="{{ $url }}">{{ $page }}</a>
@endif
@endforeach
@endif
@endforeach
{{-- Next Page Link --}}
@if ($paginator->hasMorePages())
<a href="{{ $paginator->nextPageUrl() }}">下一页</a>
@else
<a href="#" style="pointer-events: none;">下一页</a>
@endif
</div>
@endif