Everything else works fine, when I search for a subreddit (category) and submit it to the database, no problem there.
But when I first load the post/create page, I get STATUS 500 on this route http://localhost/reddit/public/data/subreddits
I'm not sure what I've done wrong considering that it works.
routes
Route::get('data/subreddits', 'PostsController@getSubreddits');
Route::get('data/subreddits/{QUERY}', 'PostsController@getSubreddits');
PostsController.php
public function create()
{
$subreddits = Subreddit::lists('name', 'id')->toArray();
return view('post/create')->with('subreddits', $subreddits);
}
public function getSubreddits($query) {
$results = Subreddit::select('id', 'name')->where('name', 'LIKE', '%' . $query . '%')->get();
return Response::json($results);
}
Javascript in create.blade.php
<script type="text/javascript">
$(document).ready(function() {
var subreddits = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: 'http://localhost/reddit/public/data/subreddits',
remote: {
url: 'http://localhost/reddit/public/data/subreddits/%QUERY',
wildcard: '%QUERY'
}
});
$('#remote .typeahead').typeahead(null, {
name: 'name',
display: 'name',
source: subreddits
});
$('#remote .typeahead').bind('typeahead:select', function(ev, suggestion) {
$('.subreddit_id').val(suggestion.id);
});
});
</script>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire