所以这是我的控制器:
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'));
}
}
和我的路线:
Route::get('posts/index', function()
{
return View::make('posts/index');
});
Route::post(
''posts/index',
array(
'as' => 'posts.index',
'uses' => 'PostsController@postSearch'
)
);
和我的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>
问题是它给我错误:
MethodNotAllowedHttpException
所以我不知道用户能够在索引页面中搜索并在表格的diffiere页面中给出结果 如何显示结果以及这个错误是什么?
答案 0 :(得分:0)
你做的一切都很好,但是在路径文件中你的类被命名为PostsController
,但实际的控制器类名是postController
这就是为什么它没有找到PostsController
。
<强>路线:强>
Route::get('posts/index', function()
{
return View::make('posts/index');
});
Route::post('posts/index', array('as' => 'posts.index','uses' => 'PostsController@postSearch'));
<强>控制器强>
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'));
}
}
查看强>
<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