Last change
on this file was 0924b6c, checked in by Özkan İliyaz <iliyaz_96@…>, 4 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
818 bytes
|
Line | |
---|
1 | <?php
|
---|
2 |
|
---|
3 | namespace App\Http\Controllers\Blog;
|
---|
4 |
|
---|
5 | use Illuminate\Http\Request;
|
---|
6 | use App\Models\Post;
|
---|
7 | use App\Http\Controllers\Controller;
|
---|
8 |
|
---|
9 | class SearchController extends Controller
|
---|
10 | {
|
---|
11 | public function __construct()
|
---|
12 | {
|
---|
13 | $this->middleware("web");
|
---|
14 | }
|
---|
15 |
|
---|
16 | public function search(Request $request)
|
---|
17 | {
|
---|
18 | $queries = explode(" ", $request->q);
|
---|
19 | $result = collect();
|
---|
20 |
|
---|
21 | foreach ($queries as $query) {
|
---|
22 | $result->push(Post::where([
|
---|
23 | "is_confirmed" => true,
|
---|
24 | "is_active" => true,
|
---|
25 | ])
|
---|
26 | ->where("title", "like", "%{$query}%")
|
---|
27 | ->get());
|
---|
28 | }
|
---|
29 |
|
---|
30 | $result = $result->flatten();
|
---|
31 |
|
---|
32 | return view("blog.search")
|
---|
33 | ->with("searchQuery", $request->q)
|
---|
34 | ->with("results", $result);
|
---|
35 | }
|
---|
36 |
|
---|
37 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.