Last active
November 17, 2015 09:33
-
-
Save jhonnrodr/7d3c19eacda9e12c236e to your computer and use it in GitHub Desktop.
Buscador
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HTML view | |
<input id="browser" name="" type="text" class="no-boarder " placeholder="Buscar Miembros" style="width:397px;"> | |
<div id="memberSearch" class="popover fade bottom in" style="top: 35px; display: none;"> | |
<div class="arrow"></div> | |
<div class="popover-content"> | |
<div id="searches" style="width:300px"> | |
</div> | |
</div> | |
</div> | |
// CSS | |
// JS | |
$("#memberSearch").mouseleave(function(){ | |
$("#memberSearch").hide(); | |
}); | |
$("#browser").click(function(){ | |
$("#memberSearch").show(); | |
}); | |
$("#browser").on('keyup',function(){ | |
var search = $(this).val(); | |
if (search!='') { | |
var dataString = search; | |
$.ajax({ | |
type: "POST", | |
url: "/search", | |
data: { search: dataString} | |
}).done(function(data){ | |
$("#searches").html(''); | |
for (i in data) { | |
// alert(data[i].name); | |
$("#searches").append("<a href='{{ URL::asset('/profile/"+data[i].id +"') }}'>"+ | |
" <div class='notification-messages success'>"+ | |
"<div class='user-profile'>"+ | |
"<img src='{{ URL::asset('uploads/profile/"+data[i].avatar+ " ' ) }}' alt='' data-src='{{ URL::asset('uploads/profile/"+data[i].avatar+" ' ) }}' data-src-retina='{{ URL::asset('uploads/profile/"+data[i].avatar+" ') }}' width='35' height='35'>"+ | |
" </div>"+ | |
"<div class='message-wrapper'>"+ | |
"<div class='heading'>"+ | |
data[i].name + ' ' + data[i].lastname + | |
"</div>"+ | |
"</div>"+ | |
"<div class='clearfix'></div>"+ | |
"</div>"+ | |
"</a>") | |
} | |
$("#memberSearch").show(); | |
}); | |
}else{ | |
$("#searches").html(''); | |
} | |
}); | |
// Backend Laravel | |
//Search Members | |
Route::post('/search', ['as' => 'user', 'uses' => 'DashboardController@search']); | |
public function search(){ | |
if(Request::ajax()){ | |
$search = Input::get('search'); | |
$query = DB::table('users')->where('name', 'LIKE', '%'.$search.'%')->where('master','=','false')->get(); | |
$searches = array(); | |
foreach ($query as $user) { | |
$searches[] = array( | |
'id' => $user->id, | |
'name' => $user->name, | |
'lastname' => $user->lastname, | |
'avatar' => $user->avatar | |
); | |
} | |
return Response::json($searches); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment