Reputation: 13
Version of Laravel 5.0 and following is my code:
My form:
<form method="get" action="{{ url('result')}}" class="search-wrap" >
<div class="form-group">
<input type="text" class="form-control search" placeholder="Search" name="key"/>
<button class="btn btn-primary submit-search text-center" type="submit">
<i class="icon-search"></i>
</button>
</div>
</form>
My controller:
use Illuminate\Http\Request;
use App\Http\Requests;
use App\products;
public function searchName(Request $request){
$key = $request->key;
$data = product::where('name','like','%'.$key.'%')->get();
return view('footwear/result',['search'=>$data]);
}
My route:
Route::get('result', 'myControler@searchName');
My view:
<?php
var_dump($search);
?>
I receive the following error: (Undefined variable: search)
Upvotes: 1
Views: 1124
Reputation: 1506
Problem is in your routes, why don't you
Try:
Route::post('result', 'myControler@searchName');
or
Route::any('result', 'myControler@searchName');
change method to post in form too, and try.
NOTE: I should have added this as comment but my rep is less than 50.
Upvotes: 1