I have an ArticleCommentsController with an index method
class ArticleCommentsController extends BaseController
{
public function index($id)
{
$comments = DB::table('comments')
->leftJoin('users', 'users.id', '=', 'comments.user_id')
->where('comments.article_id', '=', $id)
->get();
return $this->response->item($comments, new CommentTransformer);
}
}
This is the transformer class
namespace App\Transformers;
use League\Fractal\TransformerAbstract;
class CommentTransformer extends TransformerAbstract{
public function transform($comment)
{
return $comment; //simplified
}
}
The response is the following error:
get_class() expects parameter 1 to be object, array given.
Obviously, i need to send an instance of the comment object when calling Fractal\transform but i don't know how to do that since laravel's raw queries only return an array or an instance of the QueryBuilder class.