完善
This commit is contained in:
@@ -20,7 +20,7 @@ class IndexController extends AdminController
|
|||||||
*/
|
*/
|
||||||
protected function grid()
|
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('id')->sortable();
|
||||||
$grid->column('cover', '图片')->image('', 60, 60);
|
$grid->column('cover', '图片')->image('', 60, 60);
|
||||||
$grid->column('category.title', '分类名称');
|
$grid->column('category.title', '分类名称');
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class IndexController extends AdminController
|
|||||||
*/
|
*/
|
||||||
protected function grid()
|
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('id', '#ID#');
|
||||||
$grid->column('cover', '封面图片')->image('', 60, 60);
|
$grid->column('cover', '封面图片')->image('', 60, 60);
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class IndexController extends AdminController
|
|||||||
{
|
{
|
||||||
return Grid::make(new Link(), function (Grid $grid) {
|
return Grid::make(new Link(), function (Grid $grid) {
|
||||||
$grid->column('id')->sortable();
|
$grid->column('id')->sortable();
|
||||||
$grid->column('title');
|
$grid->column('title', '标题');
|
||||||
$grid->column('url');
|
$grid->column('url');
|
||||||
$grid->column('created_at');
|
$grid->column('created_at');
|
||||||
$grid->column('updated_at')->sortable();
|
$grid->column('updated_at')->sortable();
|
||||||
|
|||||||
@@ -9,42 +9,16 @@ use Illuminate\Http\Request;
|
|||||||
class ArticleController extends Controller
|
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)
|
public function show(Article $article)
|
||||||
{
|
{
|
||||||
if ($article->url) {
|
if ($article->url) {
|
||||||
return redirect($article->url);
|
return redirect($article->url);
|
||||||
}
|
}
|
||||||
|
|
||||||
$category = $article->category;
|
$category = $article->category;
|
||||||
|
$parent = $category->getTop();
|
||||||
|
|
||||||
$next = Article::where('id', '>', $article->id)->where('status', 1)->first();
|
return view('articles.show', compact('article', 'category', 'parent'));
|
||||||
|
|
||||||
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'));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
33
app/Http/Controllers/CategoryController.php
Normal file
33
app/Http/Controllers/CategoryController.php
Normal 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'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -57,4 +57,16 @@ class Category extends Model
|
|||||||
return $this->hasMany(__CLASS__, 'parent_id');
|
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
1110
new_caauto.sql
Normal file
File diff suppressed because one or more lines are too long
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -4,23 +4,46 @@
|
|||||||
|
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<!-- content -->
|
<!-- 详情 -->
|
||||||
<div class="container details">
|
<div class="details">
|
||||||
<!-- 文章标题 -->
|
<div class="contant">
|
||||||
<h3 class="details-title">{{ $article->title }}</h3>
|
<div class="page-left">
|
||||||
<p class="details-time">{{ $article->created_at }}</p>
|
<div class="pagelist">
|
||||||
<!-- 文章详情 -->
|
<h1>{{ $parent->title }}</h1>
|
||||||
<div class="details-content">
|
<ul class="listbox">
|
||||||
<img src="{{ $article->cover_path }}">
|
@if ($parent->children->isNotEmpty())
|
||||||
|
@foreach ($parent->children as $children)
|
||||||
{!! $article->content !!}
|
<li @if($category->id==$children->id) class="active" @endif>
|
||||||
</div>
|
<a href="{{ $children->link }}">{{ $children->title }}</a>
|
||||||
<!-- 下一篇 -->
|
</li>
|
||||||
@if ($next)
|
@endforeach
|
||||||
<div class="details-writings">
|
@endif
|
||||||
|
</ul>
|
||||||
<a href="{{ $next->link }}">下一篇:{{ $next->title }}</a>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
<div class="page-right">
|
||||||
|
<div class="pagelujing">
|
||||||
|
<div class="name">{{ $category->title }}</div>
|
||||||
|
<span>
|
||||||
|
您当前所在位置:<a href="/">首页</a> >
|
||||||
|
@if ($category->id!=$parent->id)
|
||||||
|
<a href="{{ $parent->link }}">{{ $parent->title }}</a> >
|
||||||
|
@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>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- end 详情 -->
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
56
resources/views/category/show.blade.php
Normal file
56
resources/views/category/show.blade.php
Normal 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> >
|
||||||
|
@if ($category->id!=$parent->id)
|
||||||
|
<a href="{{ $parent->link }}">{{ $parent->title }}</a> >
|
||||||
|
@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
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
</li>
|
</li>
|
||||||
@endforeach
|
@endforeach
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
32
resources/views/layouts/pagination.blade.php
Normal file
32
resources/views/layouts/pagination.blade.php
Normal 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
|
||||||
Reference in New Issue
Block a user