Simple search with Build a simple form using GET as well. Simple Example
Step 1 - in view/index.blade.php blade file
<form action="" method="GET"> <input type="text" name="category" required/> <button type="submit">Submit</button> </form> @foreach($users as $index => $user) @endforeach
Step 2 - In your controller you do
public function index(Request $request){ $category = $request->input('category'); $users = User::where('category', 'LIKE', '%' . $category . '%')->get(); return view('index', compact('users')); }
Eager loading will work only if you have your relationships setup properly.
Keep your route unchanged the way it is now.
No comments:
Post a Comment