初步完成
This commit is contained in:
@@ -3,43 +3,49 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\ArticlePicture;
|
||||
use App\Models\Category;
|
||||
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);
|
||||
->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;
|
||||
return view('articles.show', compact('article', 'category'));
|
||||
|
||||
$next = Article::where('id', '>', $article->id)->where('status', 1)->first();
|
||||
$parent = getTopCate($category->id);
|
||||
|
||||
return view('articles.show', compact('article', 'category', 'next', 'parent'));
|
||||
}
|
||||
|
||||
public function category(Category $category)
|
||||
//搜索
|
||||
public function search(Request $request)
|
||||
{
|
||||
$article = Article::where('category_id', $category->id)->first();
|
||||
$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'));
|
||||
}
|
||||
|
||||
public function picture(Category $category)
|
||||
{
|
||||
$articles = ArticlePicture::where('category_id', $category->id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate(12);
|
||||
return view('articles.picture', compact('articles', 'category'));
|
||||
}
|
||||
|
||||
public function picshow(ArticlePicture $article)
|
||||
{
|
||||
return view('articles.picshow', compact('article'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user