我在我的主页上有一个搜索框,当我点击搜索按钮时,视图不会返回任何结果。laravel 5.3基本网址的发布请求
这是我的形式:
{!! Form::open(array('action' => '[email protected]', 'method' => 'post', 'class' => 'form-inline', 'id' => 'search-bar')) !!}
{{ csrf_field() }}
{{Form::select('Location', ['Kasarani','Allsoaps'], null, ['class' => 'form-control', 'placeholder' => 'Location'])}}
{{ Form::select('Size', ['Bedsitter'], null, ['class' => 'form-control', 'placeholder' => 'Size']) }}
{{Form::submit('search', array('class' => 'btn btn-success'))}}
{!! Form::close() !!}
这是我的路线:
Route::get('/', '[email protected]')->name('home.index');
Route::post('/', '[email protected]')->name('home.post.index');
这是我的控制器:
public function postIndex(){
$Location = Input::get('Location');
$Size = Input::get('Size');
$validator= Validator::make(
array(
'Location'=>$Location,
'Size'=>$Size
),
array(
'Location'=>'required',
'Size'=>'required'
)
);
if ($validator->fails()) {
return redirect()->route('home.index')->withErrors($validator);
// echo "fail";
}else{
$houses=DB::table('houses')->where('Location', $Location)->where('Size', $Size)->get();
return View('pages.home')->withHouse($houses);
}
}
有谁知道我缺少的是什么?
如果你'DD($位置);'或'DD($大小); '在postIndex()里面(在重定向之前),你看到什么了吗? –
你可以分享你的视图代码和'房子'表结构吗? – Sandeesh