first
This commit is contained in:
45
app/Http/Controllers/ArticleController.php
Normal file
45
app/Http/Controllers/ArticleController.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Article;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ArticleController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示分类
|
||||
* @param \App\Models\Article $article
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View [type] [description]
|
||||
*/
|
||||
public function show(Article $article)
|
||||
{
|
||||
$category = $article->category;
|
||||
$parent = getTopCate($category->id);
|
||||
|
||||
$next = Article::where('id', '>', $article->id)
|
||||
->where('category_id', $article->category_id)
|
||||
->where('status', 1)
|
||||
->first();
|
||||
|
||||
return view('article.show', compact('article', 'next', 'parent', 'category'));
|
||||
|
||||
}
|
||||
|
||||
//搜索
|
||||
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('article.search', compact('articles'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user