I managed to integrate Typeahead.js with my laravel app. But unfortunately, I need to submit its ID instead of its name. I need to retrieve the name of the category with Typeahead but insert its ID in the database because that's how I'm referencing it.
So far I am getting an sql error because it's expecting an integer but instead it's getting a string (name of the category).
I tried doing a foreach and assign $result->id to data[] but that didn't work at all.
How can I fix that?
getSubreddits method in PostsController
public function getSubreddits($query) {
$results = Subreddit::select('name')->where('name', 'LIKE', '%' . $query . '%')->get();
return Response::json($results);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire