I am developing an application using Laravel and AngularJS.
My problem is that I want to get all information from a table for a certain user.
In the routes.php file I have declared a group so that I can reach all comments by going to:
localhost/project/public/api/comments.
I also want to be able to get all comments by a given user by going to:
localhost/project/public/api/comment/id.
Route::group(array('prefix' => 'api'), function() {
Route::resource('comments', 'CommentController', array('only' => array('index', 'store', 'destroy')));
Route::get('comment/{id}', function($id) {
$col = 'user_id';
return Comments::where($col, '=', $id);
});
}
When using this code I get the error:
ErrorException
Object of class Illuminate\Database\Eloquent\Builder could not be converted to string
I can receive the first result by adding:
return Comment::where($col, '=', $id)->first();
But I want to receive all comments for the given user. How can this be done.
->get())