我的主页上有一个搜索框,当我点击搜索按钮时,视图不会返回任何结果。
这是我的表格:
{!! Form::open(array('action' => 'PagesController@postIndex', '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('/', 'PagesController@getIndex')->name('home.index');
Route::post('/', 'PagesController@postIndex')->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);
}
}
有谁知道我错过了什么?
答案 0 :(得分:0)
当我dd($ location)时,我看到'1'
以下是我的观点:
Study - User - zip file - Last date modified
123,
user1,
New Compressed (zipped) Folder.zip,
05-24-17
123,
user2,
Iam.zip,
05-19-17
abcd,
Letsee.zip,
05-22-17
Here,
whichTwo.zip,
06-01-17
我的房子表
id |位置|尺寸| Created_at |的updated_at
答案 1 :(得分:0)
我弄清楚了:laravel的奥秘..!..问题出在我的表单中,最初选择表单返回了数组的索引。我创建了一个关联数组,现在它返回实际的位置和大小:
这是我的新表格:
{!! Form::open(array(
'class' => 'form-inline',
'url' => ' ',
'method' => 'post',
'id' => 'search-bar'
)) !!}
{{ csrf_field() }}
{{ Form::select (
'Location',
[
'Kasarani' => 'Kasarani',
'Allsoaps' => 'Allsoaps',
'Juja' => 'Juja'
],
null,
[
'class' => 'form-control',
'placeholder' => 'Location',
'required' => ''
]
) }}
{{ Form::select(
'Size',
[
'Bedsitter' => 'Bed sitter',
'Onebedroom' => 'One Bedroom',
'Twobedroom' => 'Two Bedroom'
],
null,
[
'class' => 'form-control',
'placeholder' => 'Size',
'required' => ''
]
) }}
{{ Form::submit('search', array('class' => 'btn btn-success')) }}
{!! Form::close() !!}