so this is my controller :
class PostsController extends BaseController
{
public function postSearch()
{
$q = Input::get('username');
$posts = DB::table('users')->whereRaw(
"MATCH(username) AGAINST(? IN BOOLEAN MODE)",
array($q)
)->get();
return View::make('posts.index', compact('posts'));
}
}
and my route :
Route::get('posts/index', function()
{
return View::make('posts/index');
});
Route::post(
''posts/index',
array(
'as' => 'posts.index',
'uses' => 'PostsController@postSearch'
)
);
and my html :
<div class="search">
{{ Form::model(null, array('route' => array('posts.index'))) }}
{{ Form::text('username', null, array( 'placeholder' => 'Search query...' )) }}
{{ Form::submit('Search') }}
{{ Form::close() }}
</div>
the problem is it give me error :
MethodNotAllowedHttpException
so i wasnt for users to be able to search in the index page and give them the result in the diffident page in a table how can i make the result appear and what is this error ?
You are doing everything fine,but in route file your class is named as PostsController
but the actual controller class name is postController
this is why it says PostsController
not found.
Route:
Route::get('posts/index', function()
{
return View::make('posts/index');
});
Route::post('posts/index', array('as' => 'posts.index','uses' => 'PostsController@postSearch'));
Controller
class PostsController extends BaseController
{
public function postSearch()
{
$q = Input::get('username');
$posts = DB::table('users')->whereRaw(
"MATCH(username) AGAINST(? IN BOOLEAN MODE)",
array($q)
)->get();
return View::make('posts.index', compact('posts'));
}
}
View
<div class="search">
{{ Form::open(array('route' => 'post.index', 'method' => 'POST', 'role' => 'search')) }}
{{ Form::text('username',null, array( 'placeholder' => 'Search query...' )) }}
{{ Form::submit('Search') }}
{{ Form::close() }}
</div>
@if(isset($posts))
@foreach($posts as $post)
{{$post->id}}
@endforeach
@endif