okey, skorzystałem z Ziggy, zrobiłem zrobiłem artisan ziggy i wyszedł plik js.
var Ziggy = {
namedRoutes: {"SitesController@index":{"uri":"\/","methods":["GET","HEAD"],"domain":null},"AuthSitesController@add_tag":{"uri":"add_tag","methods":["GET","HEAD"],"domain":null},"AuthSitesController.save":{"uri":"add_films","methods":["POST"],"domain":null},"AjaxTagController.gettag":{"uri":"gettag","methods":["POST"],"domain":null},"login":{"uri":"login","methods":["GET","HEAD"],"domain":null},"logout":{"uri":"logout","methods":["POST"],"domain":null},"register":{"uri":"register","methods":["GET","HEAD"],"domain":null},"password.request":{"uri":"password\/reset","methods":["GET","HEAD"],"domain":null},"password.email":{"uri":"password\/email","methods":["POST"],"domain":null},"password.reset":{"uri":"password\/reset\/{token}","methods":["GET","HEAD"],"domain":null},"password.update":{"uri":"password\/reset","methods":["POST"],"domain":null},"password.confirm":{"uri":"password\/confirm","methods":["GET","HEAD"],"domain":null},"home":{"uri":"home","methods":["GET","HEAD"],"domain":null}},
baseUrl: 'http://localhost/',
baseProtocol: 'http',
baseDomain: 'localhost',
basePort: false,
defaultParameters: []
};
if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') {
for (var name in window.Ziggy.namedRoutes) {
Ziggy.namedRoutes[name] = window.Ziggy.namedRoutes[name];
}
}
$(function() {
$( "#tag" ).autocomplete({
source: "route('AjaxTagController.gettag'); "
});
});
var id = 0;
$("#addTag").click(function(){
if($("#tag").val() ) {
id++;
var li = document.createElement("li");
li.className = "tags";
li.setAttribute("id", id);
var i = document.createElement("INPUT");
i.setAttribute("name","multiTag[]");
i.setAttribute("type","hidden");
i.setAttribute("id", id);
var tag = document.getElementById('tag').value;
li.innerHTML = " " + tag + ' <button class=\"deleteTag btn-delete\" id=\"'+id+'\">X</button>'
i.setAttribute("value", tag);
$("#tagList").append(li)
$("#tagList").append(i)
$('#tag').val('');
}});
$("#tagList").on('click', 'button.deleteTag', function() {
var idDiv = this.id;
$("#"+idDiv).remove()
$(":input[id='"+idDiv+"']").remove();
});
$("#tagList").on('click', 'button.deleteTagExsit', function() {
var del_id = this.id;
var toDel = del_id.replace('id_', '');
$("#id_"+toDel).remove();
$.ajax({
type:'POST',
url:'modules/script/query/delete-tag.php',
data:'delete_id='+toDel
});
});
Problem niestety nie rozwiązany bo dalej jest "route('AjaxTagController.gettag');%20?term=s" plik jest w osobnym plikiem po za blade mam jeszcze pytanie czy dobrze zrobiłem route jeśli zapytanie idzie get? zmiast post? nie będzie problemu z routem? bo dodaje "%20?term=s"
okey zrobiłem to w jednym pliku. W app. blade mam <script src="{{ asset('js/app.js') }}" ></script> niestety w add.blade musiałem dodać <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" ></script> ponieważ nie mogę ogarnąć dlaczego cały czas jest "$ is not defined" podobno laravel ma wbudowany jquery jeśli próbuje dodać lokalnie ui to przestają działać funkcje toptill nie wiedzieć czemu. Ale do rzeczy
<script>
$(function() {
$( "#tag" ).autocomplete({
source: "{{route('AjaxTagController.gettag')}}"
});
});
var id = 0;
$("#addTag").click(function(){
if($("#tag").val() ) {
id++;
var li = document.createElement("li");
li.className = "tags";
li.setAttribute("id", id);
var i = document.createElement("INPUT");
i.setAttribute("name","multiTag[]");
i.setAttribute("type","hidden");
i.setAttribute("id", id);
var tag = document.getElementById('tag').value;
li.innerHTML = " " + tag + ' <button class=\"deleteTag btn-delete\" id=\"'+id+'\">X</button>'
i.setAttribute("value", tag);
$("#tagList").append(li)
$("#tagList").append(i)
$('#tag').val('');
}});
$("#tagList").on('click', 'button.deleteTag', function() {
var idDiv = this.id;
$("#"+idDiv).remove()
$(":input[id='"+idDiv+"']").remove();
});
$("#tagList").on('click', 'button.deleteTagExsit', function() {
var del_id = this.id;
var toDel = del_id.replace('id_', '');
$("#id_"+toDel).remove();
$.ajax({
type:'POST',
url:'modules/script/query/delete-tag.php',
data:'delete_id='+toDel
});
});
</script>
i
$searchTerm = $request -> get('term');
$tags = DB::table('tags')
->where('name', 'like', '%'.$searchTerm.'%')
->get();
$output = '<ul class="dropdown-menu"
style="display:block;
position:relative">';
foreach ($tags as $data) {
$output .='<li>'.$data->name.'<li>';
$data->name;
$data->id;
}
$output .='<ul>';
i input o classie "form-control ui-autocomplete-input" wyrzuca "No search results." mimo że w konsoli pokazuję listę li to nie widać nic w polu input :/