Following my code.. i am trying to get array by clicking checkbox. i got array. but in two different. please check my controller. i need when i click on 2 different checkbox it will get two different array. after final result get merge itself. i tried but get where i am wrong. please help.
Checkbox
<li class="lib">
<label><input class="genreTag" id="" data-slug="mood-emotion" type="checkbox" name="" value="}">} () </label>
</li>
<li class="lib">
<label><input class="genreTag" id="" data-slug = "music-genre" type="checkbox" name="" value="}">} () </label>
</li>
//Sidebar Filter Genre Tracks
$(document).ready(function () {
$('.genreTag').on('change', function (e)
{
displayLoader();
$('input.filter-playlist').each(function() {
var $this = $(this);
$this.prop('checked', false);
$this.parent().find('> div').removeClass('chk-checked').addClass('chk-unchecked');
});
e.preventDefault();
id = [];
slug = [];
$('.genreTag:checked').each(function()
{
id.push($(this).attr('id'));
slug.push($(this).attr('data-slug'));
});
$.get("/genre-tags/", {id: id,slug: slug}, function(data)
{
hideLoader();
refreshedPage = $(data);
newDemo = refreshedPage.find(".libraryWrapper, .albumWrapper, .composersWrapper, .albumsListWrapper, .albumsWrapper, .accountWrapper, .distributionsWrapper, .PaymentsWrapper, .contactWrapper, .contractsWrapper, .toolsWrapper, .blogWrapper, .pageWrapper, .cartWrapper, .pageWrapper").html();
$('.libraryWrapper, .albumsWrapper, .albumWrapper, .composersWrapper, .albumsListWrapper, .accountWrapper, .distributionsWrapper, .PaymentsWrapper, .contactWrapper, .contractsWrapper, .toolsWrapper, .blogWrapper, .pageWrapper, .cartWrapper, .pageWrapper').html(newDemo);
activatePlayer()
initTrackInfo();
});
});
});
Controller
public function genresFilter ()
{
$sortBy = Input::get('sortBy', 'id');
$dir = Input::get('direction', 'desc');
$orderBy = [
'tracks'=>[ 'order_by'=>$sortBy, 'direction'=>$dir ]
];
$id = Input::get('id');
$slug = Input::get('slug');
if(!is_array($id)) {
$id = [];
$tag = [];
} else {
foreach($slug as $key => $slug) {
$category = Category::where('slug', $slug)->first();
$tag = Tag::with('tracks','elements')->where('category_id', $category->id)->whereIn('id', $id)->get();
}
}
echo "<pre>";
print_r($tag->toArray());
die();
$this->layout->content = View::make('public.tags.genres', compact('tag'));
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire