天山网艾克

4813 经验值

Dingo 和 JWT 用的时候, 比如说预览页面需要 当前Id的稿件, 还有下面一堆相关新闻, 这时候, 相关新闻 怎么解决?
public function transform(Article $article) { }
调用这个的时候 只有一个对象, 列表 怎么获取? 列表当然还有一些格式要求; 求助

public function index($category_id =0,$page_size = 10)
{
    $articles =  Article::with('getCategory')->where('category_id',$category_id)->paginate($page_size);
    return $this->response->paginator($articles,new ArticleTransformer(),[],function ($resource,$fractal){
       return $fractal->setSerializer(new ArticleSerializer());
    });
}

我写了 这样 起作用了, 我得理解一下 [] 这个玩意儿

public function index($category_id =0,$page_size = 10)
{
    $articles =  Article::with('getCategory')->where('category_id',$category_id)->paginate($page_size);
    return $this->response->paginator($articles,new ArticleTransformer(),function ($resource,$fractal){
       return $fractal->setSerializer(new ArticleSerializer());
    });
}

Argument 3 passed to Dingo\\Api\\Http\\Response\\Factory::paginator() must be of the type array, object given, called in /Users/abdureshid/Projects/TsCms/app/Api/Controllers/ArticleController.php on line 26 and defined

public function index($category_id =0)
{
    $articles =  Article::with('getCategory')->where('category_id',$category_id)->paginate(1);
    return $this->response->paginator($articles->items(),new ArticleTransformer(),function ($resource,$fractal){
       return $fractal->setSerializer(new ArticleSerializer());
    });
}

Argument 1 passed to Dingo\\Api\\Http\\Response\\Factory::paginator() must implement interface Illuminate\\Contracts\\Pagination\\Paginator, array given, called in /Users/abdureshid/Projects/TsCms/app/Api/Controllers/ArticleController.php on line 24 and defined"

出现这个问题, 真不知道怎么解决

这个时候出现问题

public function index($category_id =0)
{
    $articles =  Article::with('getCategory')->where('category_id',$category_id)->paginate(1);
    return $this->collection($articles, new ArticleTransformer(), function ($resource, $fractal) {
        $fractal->setSerializer(new ArticleSerializer());
    });
}

Argument 1 passed to Dingo\\Api\\Http\\Response\\Factory::collection() must be an instance of Illuminate\\Support\\Collection, instance of Illuminate\\Pagination\\LengthAwarePaginator given

public function index($category_id =0)
    {
        $articles =  Article::with('getCategory')->where('category_id',$category_id)->paginate(1);
        return $this->collection($articles, new ArticleTransformer(), function ($resource, $fractal) {
            $fractal->setSerializer(new ArticleSerializer());
        });
    }
$articles =  Article::with('getCategory')->where('category_id',$category_id)->paginate(1);
        return $this->collection($articles, new ArticleTransformer(), function ($resource, $fractal) {
            $fractal->setSerializer(new ArticleSerializer());
        });

稿件分页 怎么实现, 我用paginate 出现 错误

”Argument 1 passed to Dingo\\Api\\Http\\Response\\Factory::collection() must be an instance of Illuminate\\Support\\Collection, instance of Illuminate\\Pagination\\LengthAwarePaginator given”

怎么解决

用bingo和JWT 的时候 , 正常json里面 status_code,message ,time 等属性?
我看了教程 除了 API的基础 上讲过 这些 但是 Bingo 和JWT 的时候没有说明,