Show your whole routes file..
Jul 20, 2016
10
Level 4
Search DB
I feel like i ask so much of this community ! And thank you to all for all your help on this road to learning this wonderful framework! But i have yet another question!
So im trying to do searches on a database , simple search form that returns results to a view
my controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\comics;
use App\Http\Requests;
class QueryController extends Controller
{
public function getIndex(Comics $request)
{
$this->validate($request, [
'search' => 'required'
]);
$search = $request->get('search');
$comics = Comics::where('title', 'like', "%$search%")
->orWhere('body', 'like', "%$search%")
->paginate(10)
;
return view('pages.search', compact('comics'));
}
}
My view for search box
<form action="/search" method="GET" role="search" style="margin-top: 40px;">
<div class="form-group">
<div class="col-md-4">
<input type="text" class="form-control" name="search" placeholder="Search" value="">
</div>
<div class="col-md-3">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</form>
and my route
Route::get('search', 'QueryController@search');
and lastly my output view
<p>
{{ $comics->count() }} {{ str_plural('comics', $comics->count()) }} matched your query
</p>
@foreach($comics as $comic)
<!--- Loop through posts and display... -->
@endforeach
<!-- Pagination links... -->
{!! $comics->appends(['search' => Input::get('search')])->render() !!}
The error im getting is
Not Found
The requested URL /search was not found on this server.
the url out is this http://localhost:8888/search?search=batman+
Thanks so much again
Please or to participate in this conversation.