文章关联多分类
This commit is contained in:
@@ -10,18 +10,19 @@ class ArticleController extends Controller
|
||||
|
||||
/**
|
||||
* 显示分类
|
||||
* @param Category $category [description]
|
||||
* @return [type] [description]
|
||||
* @param \App\Models\Article $article
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View [type] [description]
|
||||
*/
|
||||
public function show(Article $article)
|
||||
{
|
||||
$parent = $category = $article->category;
|
||||
if ($category->childrens->isEmpty()) {
|
||||
$parent = $category->parent;
|
||||
}
|
||||
$advert = Advert::where('category_id',73)->first();
|
||||
// $parent = $category = $article->category;
|
||||
// if ($category->childrens->isEmpty()) {
|
||||
// $parent = $category->parent;
|
||||
// }
|
||||
// $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'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,6 @@ class CategoryController extends Controller
|
||||
$parent = $category->parent;
|
||||
}
|
||||
|
||||
$advert = Advert::where('category_id', 73)->first();
|
||||
|
||||
return view('category.show', compact('articles', 'category', 'parent'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ class IndexController extends Controller
|
||||
//通用获取文章
|
||||
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')
|
||||
->orderBy('created_at', 'desc')
|
||||
->take($take)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\ArticleCategory;
|
||||
use App\Models\Category;
|
||||
use App\Models\DedeArchive;
|
||||
use App\Models\DedeArctype;
|
||||
@@ -11,6 +12,7 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
|
||||
use Tree;
|
||||
|
||||
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()
|
||||
{
|
||||
$article = Article::find(913);
|
||||
dd($article->get_one_cover());
|
||||
dd();
|
||||
$lists = Category::where('created_at','2020-06-03 15:57:55')->get();
|
||||
$i=1;
|
||||
foreach ($lists as $info){
|
||||
$old = DedeArctype::select('id', 'reid as parent_id', 'typename as title', 'content')->find($info->oldid);
|
||||
$cate = Category::where('oldid',$old->parent_id)->first();
|
||||
$lists = Category::where('created_at', '2020-06-03 15:57:55')->get();
|
||||
$i = 1;
|
||||
foreach ($lists as $info) {
|
||||
$old = DedeArctype::select('id', 'reid as parent_id', 'typename as title', 'content')
|
||||
->find($info->oldid);
|
||||
$cate = Category::where('oldid', $old->parent_id)->first();
|
||||
$info->parent_id = $cate->id;
|
||||
$info->save();
|
||||
$i++;
|
||||
@@ -38,14 +57,17 @@ class TestController extends Controller
|
||||
dump(count($lists));
|
||||
dd();
|
||||
$cateids = Category::where('oldid', '>', 0)->pluck('oldid');
|
||||
$oldids = DedeArctype::where('ishidden', 0)->pluck('id');
|
||||
$diffids = array_diff($oldids->toArray(), $cateids->toArray());
|
||||
$oldids = DedeArctype::where('ishidden', 0)->pluck('id');
|
||||
$diffids = array_diff($oldids->toArray(), $cateids->toArray());
|
||||
dump(count($cateids));
|
||||
dump(count($oldids));
|
||||
dump($diffids);
|
||||
|
||||
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);
|
||||
Category::create($data);
|
||||
}
|
||||
@@ -87,9 +109,9 @@ class TestController extends Controller
|
||||
{
|
||||
$lists = Article::where('category_id', 0)->get();
|
||||
foreach ($lists as $list) {
|
||||
$old = DedeArchive::find($list->oldid);
|
||||
$cate = Category::where('oldid',$old->typeid)->first();
|
||||
$list ->category_id = $cate->id;
|
||||
$old = DedeArchive::find($list->oldid);
|
||||
$cate = Category::where('oldid', $old->typeid)->first();
|
||||
$list->category_id = $cate->id;
|
||||
$list->save();
|
||||
}
|
||||
dd();
|
||||
@@ -100,7 +122,7 @@ class TestController extends Controller
|
||||
dump(count($oldids));
|
||||
dump($diffids);
|
||||
die();
|
||||
$map = [
|
||||
$map = [
|
||||
'id' => ['in', $diffids],
|
||||
];
|
||||
$list = DedeArchive::whereIn('id', $diffids)->get();
|
||||
@@ -130,7 +152,7 @@ class TestController extends Controller
|
||||
dd('已经导入过数据');
|
||||
}
|
||||
$categorys = Category::get();
|
||||
$error = $success = [];
|
||||
$error = $success = [];
|
||||
DedeArchive::whereNotNull('litpic')->chunk(200, function ($articles) use ($categorys) {
|
||||
|
||||
foreach ($articles as $article) {
|
||||
@@ -170,7 +192,9 @@ class TestController extends Controller
|
||||
if ($categorys->count()) {
|
||||
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);
|
||||
|
||||
foreach ($list as $key => $value) {
|
||||
@@ -193,6 +217,7 @@ class TestController extends Controller
|
||||
'content' => $category['content'],
|
||||
'status' => 1,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user