文章关联多分类

This commit is contained in:
2021-04-02 10:35:51 +08:00
parent 28035e7a26
commit 96793afeec
20 changed files with 334 additions and 431 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Admin\Controllers\Article; namespace App\Admin\Controllers\Article;
use App\Admin\Selectable\CategorySelectAble;
use App\Models\Article; use App\Models\Article;
use App\Models\Category; use App\Models\Category;
use Encore\Admin\Controllers\AdminController; use Encore\Admin\Controllers\AdminController;
@@ -20,7 +21,7 @@ class IndexController extends AdminController
$grid->filter(function ($filter) { $grid->filter(function ($filter) {
$filter->column(1 / 2, function ($filter) { $filter->column(1 / 2, function ($filter) {
$filter->like('title', '文章标题'); $filter->like('title', '文章标题');
$filter->like('category_id', '所属分类')->select(Category::selectOptions(function ($model) { $filter->equal('categories.id', '所属分类')->select(Category::selectOptions(function ($model) {
return $model->where('status', 1)->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]); return $model->where('status', 1)->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
}, '所有分类')); }, '所有分类'));
}); });
@@ -30,7 +31,9 @@ class IndexController extends AdminController
$grid->column('id', '#ID#'); $grid->column('id', '#ID#');
$grid->column('cover', '封面图片')->image('', 100); $grid->column('cover', '封面图片')->image('', 100);
$grid->column('category.title', '所属分类'); $grid->column('所属分类')->display(function () {
return $this->categories()->pluck('title');
})->label();
$grid->column('title', '文章标题'); $grid->column('title', '文章标题');
$states = [ $states = [
'on' => ['value' => 1, 'text' => '打开', 'color' => 'primary'], 'on' => ['value' => 1, 'text' => '打开', 'color' => 'primary'],
@@ -48,14 +51,8 @@ class IndexController extends AdminController
$form = new Form(new Article); $form = new Form(new Article);
$form->text('title', '文章标题')->rules('min:2'); $form->text('title', '文章标题')->rules('min:2');
$form->select('category_id', '所属分类') $form->belongsToMany('categories', CategorySelectAble::class, __('关联分类'));
->options(Category::selectOptions(function ($model) {
return $model->where('status', 1)->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
}, '选择分类'))
->rules('required|min:1', [
'required' => '必须选择所属分类',
'min' => '必须选择所属分类',
]);
$form->textarea('description', '内容简介'); $form->textarea('description', '内容简介');
$form->image('cover', '封面') $form->image('cover', '封面')
->move('images/' . date('Y/m/d')) ->move('images/' . date('Y/m/d'))

View File

@@ -38,7 +38,7 @@ class IndexController extends AdminController
->when('show', function (WidgetsForm $form) { ->when('show', function (WidgetsForm $form) {
$form->select('article_id', '关联文章') $form->select('article_id', '关联文章')
->options(function ($option, $info) { ->options(function ($option, $info) {
return Article::whereHas('category', function ($q) { return Article::whereHas('categories', function ($q) {
$q->where('type', 'show'); $q->where('type', 'show');
})->pluck('title', 'id'); })->pluck('title', 'id');
})->help('当分类类型是文章详情的时候需要选择关联文章'); })->help('当分类类型是文章详情的时候需要选择关联文章');
@@ -101,7 +101,7 @@ class IndexController extends AdminController
->when('show', function (Form $form) { ->when('show', function (Form $form) {
$form->select('article_id', '关联文章') $form->select('article_id', '关联文章')
->options(function ($option, $info) { ->options(function ($option, $info) {
return Article::whereHas('category', function ($q) { return Article::whereHas('categories', function ($q) {
$q->where('type', 'show'); $q->where('type', 'show');
})->pluck('title', 'id'); })->pluck('title', 'id');
})->help('当分类类型是文章详情的时候需要选择关联文章'); })->help('当分类类型是文章详情的时候需要选择关联文章');

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Admin\Selectable;
use App\Models\Category;
use Encore\Admin\Grid\Filter;
use Encore\Admin\Grid\Selectable;
class CategorySelectAble extends Selectable
{
public $model = Category::class;
public static function display()
{
return function ($value) {
if (is_array($value)) {
return implode(';', array_column($value, 'title'));
}
return optional($this->categories)->title;
};
}
public function make()
{
$this->model()->where('status', 1);
$this->column('id', 'ID');
$this->column('title', '分类名称');
$this->column('type', '类型')->using(Category::TYPES);
$this->filter(function (Filter $filter) {
$filter->like('title', '分类名称');
$filter->equal('parent.id', '所属分类')
->select(Category::selectOptions(function ($model) {
return $model->where('status', 1)
->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
}, '所有分类'));
$filter->equal('type', '类型')->select(Category::TYPES);
});
}
}

View File

@@ -27,7 +27,9 @@ function getOneCategory($categoryId, $return = '')
*/ */
function getOneArticleBYCate($categoryId, $result = '') function getOneArticleBYCate($categoryId, $result = '')
{ {
$info = Article::where('category_id', $categoryId)->latest('sort')->latest()->first(); $info = Article::where('status', 1)
->ByCategory($categoryId)
->latest('sort')->latest()->first();
if ($info) { if ($info) {
if ($result) { if ($result) {
@@ -53,8 +55,8 @@ function getOneArticleBYCate($categoryId, $result = '')
function getArticlesBYCate($categoryId, $take = 8, $mark = 'one') function getArticlesBYCate($categoryId, $take = 8, $mark = 'one')
{ {
if ($mark == 'one') { if ($mark == 'one') {
$articles = Article::where('category_id', $categoryId) $articles = Article::where('status', 1)
->where('status', 1) ->ByCategory($categoryId)
->latest('sort') ->latest('sort')
->latest() ->latest()
->take($take) ->take($take)
@@ -63,8 +65,8 @@ function getArticlesBYCate($categoryId, $take = 8, $mark = 'one')
$cate = Category::find($categoryId); $cate = Category::find($categoryId);
$ids = $cate->getAllChildrenId(); $ids = $cate->getAllChildrenId();
$articles = Article::whereIn('category_id', $ids) $articles = Article::where('status', 1)
->where('status', 1) ->ByCategory($ids)
->latest('sort') ->latest('sort')
->latest() ->latest()
->take($take) ->take($take)

View File

@@ -10,18 +10,19 @@ class ArticleController extends Controller
/** /**
* 显示分类 * 显示分类
* @param Category $category [description] * @param \App\Models\Article $article
* @return [type] [description] * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View [type] [description]
*/ */
public function show(Article $article) public function show(Article $article)
{ {
$parent = $category = $article->category; // $parent = $category = $article->category;
if ($category->childrens->isEmpty()) { // if ($category->childrens->isEmpty()) {
$parent = $category->parent; // $parent = $category->parent;
} // }
$advert = Advert::where('category_id',73)->first(); // $advert = Advert::where('category_id',73)->first();
return view('article.show', compact('article', 'parent', 'category','advert')); return view('article.show', compact('article'));
// return view('article.show', compact('article', 'parent', 'category','advert'));
} }

View File

@@ -1,40 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ConfirmsPasswords;
class ConfirmPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Confirm Password Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password confirmations and
| uses a simple trait to include the behavior. You're free to explore
| this trait and override any functions that require customization.
|
*/
use ConfirmsPasswords;
/**
* Where to redirect users when the intended url fails.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
}

View File

@@ -1,22 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
}

View File

@@ -1,40 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}

View File

@@ -1,73 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}

View File

@@ -1,30 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ResetsPasswords;
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Where to redirect users after resetting their password.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
}

View File

@@ -1,42 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\VerifiesEmails;
class VerificationController extends Controller
{
/*
|--------------------------------------------------------------------------
| Email Verification Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling email verification for any
| user that recently registered with the application. Emails may also
| be re-sent if the user didn't receive the original email message.
|
*/
use VerifiesEmails;
/**
* Where to redirect users after verification.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}
}

View File

@@ -24,8 +24,6 @@ class CategoryController extends Controller
$parent = $category->parent; $parent = $category->parent;
} }
$advert = Advert::where('category_id', 73)->first();
return view('category.show', compact('articles', 'category', 'parent')); return view('category.show', compact('articles', 'category', 'parent'));
} }
} }

View File

@@ -29,7 +29,8 @@ class IndexController extends Controller
//通用获取文章 //通用获取文章
public function getArticle($category_ids, $take = 3) public function getArticle($category_ids, $take = 3)
{ {
return Article::whereIn('category_id', $category_ids) return Article::where('status', 1)
->ByCategory($category_ids)
->select('id', 'description', 'title', 'created_at', 'cover', 'content') ->select('id', 'description', 'title', 'created_at', 'cover', 'content')
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->take($take) ->take($take)

View File

@@ -3,6 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Article; use App\Models\Article;
use App\Models\ArticleCategory;
use App\Models\Category; use App\Models\Category;
use App\Models\DedeArchive; use App\Models\DedeArchive;
use App\Models\DedeArctype; use App\Models\DedeArctype;
@@ -11,6 +12,7 @@ use Illuminate\Support\Facades\DB;
class TestController extends Controller class TestController extends Controller
{ {
use Tree; use Tree;
public function index() public function index()
@@ -18,17 +20,34 @@ class TestController extends Controller
} }
public function set_article_category()
{
$articles = Article::whereHas('category')
->chunk(200, function ($articles) {
foreach ($articles as $article) {
ArticleCategory::create([
'article_id' => $article->id,
'category_id' => $article->category_id,
]);
}
});
return true;
}
//检查分类 //检查分类
public function checkCategory() public function checkCategory()
{ {
$article = Article::find(913); $article = Article::find(913);
dd($article->get_one_cover()); dd($article->get_one_cover());
dd(); dd();
$lists = Category::where('created_at','2020-06-03 15:57:55')->get(); $lists = Category::where('created_at', '2020-06-03 15:57:55')->get();
$i=1; $i = 1;
foreach ($lists as $info){ foreach ($lists as $info) {
$old = DedeArctype::select('id', 'reid as parent_id', 'typename as title', 'content')->find($info->oldid); $old = DedeArctype::select('id', 'reid as parent_id', 'typename as title', 'content')
$cate = Category::where('oldid',$old->parent_id)->first(); ->find($info->oldid);
$cate = Category::where('oldid', $old->parent_id)->first();
$info->parent_id = $cate->id; $info->parent_id = $cate->id;
$info->save(); $info->save();
$i++; $i++;
@@ -38,14 +57,17 @@ class TestController extends Controller
dump(count($lists)); dump(count($lists));
dd(); dd();
$cateids = Category::where('oldid', '>', 0)->pluck('oldid'); $cateids = Category::where('oldid', '>', 0)->pluck('oldid');
$oldids = DedeArctype::where('ishidden', 0)->pluck('id'); $oldids = DedeArctype::where('ishidden', 0)->pluck('id');
$diffids = array_diff($oldids->toArray(), $cateids->toArray()); $diffids = array_diff($oldids->toArray(), $cateids->toArray());
dump(count($cateids)); dump(count($cateids));
dump(count($oldids)); dump(count($oldids));
dump($diffids); dump($diffids);
foreach ($diffids as $diffid) { foreach ($diffids as $diffid) {
$info = DedeArctype::where('id',$diffid)->where('ishidden', 0)->select('id', 'reid as parent_id', 'typename as title', 'content')->first(); $info = DedeArctype::where('id', $diffid)
->where('ishidden', 0)
->select('id', 'reid as parent_id', 'typename as title', 'content')
->first();
$data = $this->getData($info); $data = $this->getData($info);
Category::create($data); Category::create($data);
} }
@@ -87,9 +109,9 @@ class TestController extends Controller
{ {
$lists = Article::where('category_id', 0)->get(); $lists = Article::where('category_id', 0)->get();
foreach ($lists as $list) { foreach ($lists as $list) {
$old = DedeArchive::find($list->oldid); $old = DedeArchive::find($list->oldid);
$cate = Category::where('oldid',$old->typeid)->first(); $cate = Category::where('oldid', $old->typeid)->first();
$list ->category_id = $cate->id; $list->category_id = $cate->id;
$list->save(); $list->save();
} }
dd(); dd();
@@ -100,7 +122,7 @@ class TestController extends Controller
dump(count($oldids)); dump(count($oldids));
dump($diffids); dump($diffids);
die(); die();
$map = [ $map = [
'id' => ['in', $diffids], 'id' => ['in', $diffids],
]; ];
$list = DedeArchive::whereIn('id', $diffids)->get(); $list = DedeArchive::whereIn('id', $diffids)->get();
@@ -130,7 +152,7 @@ class TestController extends Controller
dd('已经导入过数据'); dd('已经导入过数据');
} }
$categorys = Category::get(); $categorys = Category::get();
$error = $success = []; $error = $success = [];
DedeArchive::whereNotNull('litpic')->chunk(200, function ($articles) use ($categorys) { DedeArchive::whereNotNull('litpic')->chunk(200, function ($articles) use ($categorys) {
foreach ($articles as $article) { foreach ($articles as $article) {
@@ -170,7 +192,9 @@ class TestController extends Controller
if ($categorys->count()) { if ($categorys->count()) {
dd('已经导入过数据'); dd('已经导入过数据');
} }
$lists = DedeArctype::where('ishidden', 0)->select('id', 'reid as parent_id', 'typename as title', 'content')->get(); $lists = DedeArctype::where('ishidden', 0)
->select('id', 'reid as parent_id', 'typename as title', 'content')
->get();
$list = Tree::list2tree($lists->toArray(), 'id', 'parent_id', 'children', 0); $list = Tree::list2tree($lists->toArray(), 'id', 'parent_id', 'children', 0);
foreach ($list as $key => $value) { foreach ($list as $key => $value) {
@@ -193,6 +217,7 @@ class TestController extends Controller
'content' => $category['content'], 'content' => $category['content'],
'status' => 1, 'status' => 1,
]; ];
return $data; return $data;
} }

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use App\Models\Traits\BelongsToCategory; use App\Models\Traits\BelongsToCategory;
use App\Models\Traits\HasOneCover; use App\Models\Traits\HasOneCover;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Article extends Model class Article extends Model
{ {
@@ -52,4 +53,35 @@ class Article extends Model
} }
/**
* Notes: 关联分类
* @Author: 玄尘
* @Date : 2021/4/2 9:11
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function categories(): BelongsToMany
{
return $this->belongsToMany(Category::class)
->using(ArticleCategory::class);
}
/**
* Notes: description
* @Author: 玄尘
* @Date : 2021/4/2 9:17
* @param $query
* @param $ids
* @return mixed
*/
public function scopeByCategory($query, $ids)
{
if (!is_array($ids)) {
$ids = [$ids];
}
return $query->whereHas('categories', function ($q) use ($ids) {
$q->whereIN('id', $ids);
});
}
} }

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\Pivot;
class ArticleCategory extends Pivot
{
//
}

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Encore\Admin\Traits\AdminBuilder; use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree; use Encore\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Category extends Model class Category extends Model
{ {
@@ -35,7 +36,7 @@ class Category extends Model
return $this->hasOne(Article::class)->where('id', $this->article_id); return $this->hasOne(Article::class)->where('id', $this->article_id);
break; break;
case self::TYPE_ARTICLE: case self::TYPE_ARTICLE:
return $this->hasMany(Article::class); return $this->belongsToMany(Article::class);
break; break;
case self::TYPE_ADVERT: case self::TYPE_ADVERT:
return $this->hasMany(Advert::class); return $this->hasMany(Advert::class);
@@ -74,4 +75,9 @@ class Category extends Model
return $ids; return $ids;
} }
public function articles(): BelongsToMany
{
return $this->belongsToMany(Article::class);
}
} }

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateArticleCategoriesTable extends Migration
{
/**
* Run the migrations.
* @return void
*/
public function up()
{
Schema::create('article_category', function (Blueprint $table) {
$table->foreignId('article_id');
$table->foreignId('category_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
* @return void
*/
public function down()
{
Schema::dropIfExists('article_categories');
}
}

View File

@@ -4,57 +4,57 @@
@section('content') @section('content')
<div class="container mg-t-b"> <div class="container mg-t-b">
<div class="page-left"> {{-- <div class="page-left">--}}
<div class="pagelist"> {{-- <div class="pagelist">--}}
<h1>{{ $parent->title }}</h1> {{-- <h1>{{ $parent->title }}</h1>--}}
<ul class="listbox"> {{-- <ul class="listbox">--}}
@if ($parent->childrens->isNotEmpty()) {{-- @if ($parent->childrens->isNotEmpty())--}}
@foreach ($parent->childrens as $child) {{-- @foreach ($parent->childrens as $child)--}}
<li @if($category->id==$child->id) class="active" @endif> {{-- <li @if($category->id==$child->id) class="active" @endif>--}}
<a href="{{ $child->link }}">{{ $child->title }}</a> {{-- <a href="{{ $child->link }}">{{ $child->title }}</a>--}}
@if ($child->childrens->isNotEmpty()) {{-- @if ($child->childrens->isNotEmpty())--}}
<ul class="dropdown"> {{-- <ul class="dropdown">--}}
@foreach ($child->childrens as $childd) {{-- @foreach ($child->childrens as $childd)--}}
<li @if($category->id==$child->id) class="active" @endif> {{-- <li @if($category->id==$child->id) class="active" @endif>--}}
<a href="{{ $childd->link }}">{{ $childd->title }}</a> {{-- <a href="{{ $childd->link }}">{{ $childd->title }}</a>--}}
</li> {{-- </li>--}}
@endforeach {{-- @endforeach--}}
</ul> {{-- </ul>--}}
@endif {{-- @endif--}}
</li> {{-- </li>--}}
@endforeach {{-- @endforeach--}}
@endif {{-- @endif--}}
</ul> {{-- </ul>--}}
</div> {{-- </div>--}}
{{-- </div>--}}
{{-- <div class="page-right">--}}
{{-- <div class="pagelujing">--}}
{{-- --}}{{-- <div class="name">{{ $category->title }}</div>--}}
{{-- <span>--}}
{{-- 您当前所在位置:<a href="/">首页</a>--}}
{{-- @if ($parent->id!=$category->id)--}}
{{-- > <a href="{{ $parent->link }}">{{ $parent->title }}</a>--}}
{{-- @endif--}}
{{-- > <a href="{{ $category->link }}">{{ $category->title }}</a>--}}
{{-- </span>--}}
{{-- </div>--}}
<div class="biaoti">{{ $article->title }}</div>
<div class="sshuomign"><span>发布时间:{{ $article->created_at->format('Y-m-d') }}</span></div>
<!-- 图片 -->
@if ($article->cover && $article->category_id==127)
<div style="width: 100%; text-align: center; margin-top: 20px;">
<img src="{{ $article->cover_path }}" style="width: 400px;">
</div>
@endif
<div class="article_txt">
{!! $article->content !!}
</div> </div>
<div class="page-right">
<div class="pagelujing">
{{-- <div class="name">{{ $category->title }}</div>--}}
<span>
您当前所在位置:<a href="/">首页</a>
@if ($parent->id!=$category->id)
> <a href="{{ $parent->link }}">{{ $parent->title }}</a>
@endif
> <a href="{{ $category->link }}">{{ $category->title }}</a>
</span>
</div>
<div class="biaoti">{{ $article->title }}</div>
<div class="sshuomign"><span>发布时间:{{ $article->created_at->format('Y-m-d') }}</span></div>
<!-- 图片 -->
@if ($article->cover && $article->category_id==127)
<div style="width: 100%; text-align: center; margin-top: 20px;">
<img src="{{ $article->cover_path }}" style="width: 400px;">
</div>
@endif
<div class="article_txt">
{!! $article->content !!}
</div>
</div>
<div class="clearfix"></div>
</div> </div>
<div class="clearfix"></div>
{{-- </div>--}}
@endsection @endsection

View File

@@ -16,6 +16,7 @@ Route::get('articles/{article}', 'ArticleController@show')->name('article.show')
Route::get('category/{category}', 'CategoryController@index')->name('category.show'); Route::get('category/{category}', 'CategoryController@index')->name('category.show');
//以下为导入数据 //以下为导入数据
Route::get('test/set_article_category', 'TestController@set_article_category');
Route::get('test/set_category', 'TestController@set_category'); Route::get('test/set_category', 'TestController@set_category');
Route::get('test/set_article', 'TestController@set_article'); Route::get('test/set_article', 'TestController@set_article');
Route::get('test/set_cate_article', 'TestController@setCateArticle'); Route::get('test/set_cate_article', 'TestController@setCateArticle');