Skip to content

Commit

Permalink
Search (The Messy Way)
Browse files Browse the repository at this point in the history
  • Loading branch information
3omarbadr committed Apr 13, 2022
1 parent 1605c16 commit 2afe83d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ class PostController extends Controller
*/
public function index()
{
$posts = Post::latest();
if(request('search')){
$posts
->where('title', 'like', '%' . request('search') . '%')
->orWhere('body', 'like', '%' . request('search') . '%');
}
return view('posts', [
'posts' => Post::latest()->get(),
'posts' => $posts->get(),
'categories' => Category::all()
]);
}
Expand Down
12 changes: 8 additions & 4 deletions resources/views/partials/posts-header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ class="py-2 pl-3 pr-9 text-sm font-semibold w-full lg:w-32 lg:inline-flex">{{iss
</path>
</g>
</svg>
</div>
</div> --}}

<!-- Search -->
<div class="relative flex lg:inline-flex items-center bg-gray-100 rounded-xl px-3 py-2">
<form method="GET" action="#">
<input type="text" name="search" placeholder="Find something"
class="bg-transparent placeholder-black font-semibold text-sm">
<input type="text"
name="search"
placeholder="Find something"
class="bg-transparent placeholder-black font-semibold text-sm"
value="{{request('search')}}"
>
</form>
</div>
</div> --}}
</div>
</header>

0 comments on commit 2afe83d

Please sign in to comment.