Merhaba ,
Sitem için fulltext search yapmaya çalışıyorum. Twitter bootstrap kullanıyorum ve typeahead kullanmak istiyorum. Fakat henüz sistemi çözemedim. Henüz hiç bir öneri alamadım ve bu öneriler ile arama fonksiyonu aynı controller action i içinde mi olacak kaygısı yaşıyorum. Teşekkür ederim.
Kodlarım
Route::post('typequery' , 'BlogController@postTypeahead');
//view
{{ Form::open(array('url' => 'searchblogs','method' => 'post','id' => "search", 'class' => "input-append")) }}
<input class="typeahead" type="text" data-provide="typeahead" data-items="4" data-page="url('typequery')" />
<input class="btn search-bt" type="submit" name="submit" value="" />
{{ Form::close() }}
//controller
public function postTypeahead()
{
// Get the query strings.
//
$column = Input::get('column');
$query = Input::get('query');
// Check if the column name is valid and make sure we have a query.
//
if ( in_array( $column, $this->valid_filters ) and strlen($query) >= 1 ):
// Initiate an empty array.
//
$data = array();
// Search the database.
//
$results = Post::select( $column )->where( $column, 'LIKE', '%' . $query . '%')->get();
// Loop through the results.
//
foreach ( $results as $result ):
$data[] = $result->$column;
endforeach;
endif;
// Return a response.
//
return new Response(array( 'data' => $data ));
}
//jquery
<script>
if ( jQuery().typeahead ) {
$('.typeahead').typeahead({
source : function(typeahead, query){
if ( typeahead.$element.data('page') !== 'undefined' ) {
$.ajax({
url : typeahead.$element.data('page'),
type : 'POST',
data : { query : query, column : typeahead.$element.attr('name') },
dataType : 'json',
async : true,
success : function(data) {
typeahead.process(data.data);
}
});
}
}
});
}
</script>