This commit is contained in:
2020-09-17 08:57:27 +08:00
parent ac3b53b163
commit a4162b5710
9 changed files with 223 additions and 157 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Models\Advert;
use App\Models\Article;
use Illuminate\Http\Request;
class ArticleController extends Controller
{
@@ -27,4 +28,18 @@ class ArticleController extends Controller
}
//搜索
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'));
}
}