您可以尝试这样的事情:
路线 :
Route::get('/search', array('as' => 'user.search', 'uses' => 'user@search'));
查看:(搜索/index.blade.php)
{{ Form::open(URL::to_route('user.search')) }}
{{ $errors->has('username') ? $errors->first('username','<span class="error">:message</span>') : '' }}
{{ Form::text('username', Input::old('username', $username), array('class' => 'input-medium')) }}
{{ Form::submit('Search'); }}
{{ Form::close() }}
@if ( isset($user) )
@foreach ($user->results as $user)
{{ $user->first_name }}
{{ $user->last_name }}
@endforeach
@endif
控制器:(控制器/user.php)
class User_Controller extends Base_Controller
{
public function action_search()
{
$data['username'] = Input::get('username');
if(Input::get())
{
$rules=array( 'username' => 'required' );
$validation = Validator::make(Input::all(), $rules);
if($validation->fails())
{
return Redirect::back()->with_errors($validation)->with_input();
}
else {
data['user'] = User::where('username', '=', Input::get('username'));
}
}
return View::make('search.index', $data);
}
}
型号:(型号/user.php)
class User extends Eloquent
{
// ...
}