我正在计划一个RESTful API,我想知道在api中提供文件/文件包的最佳方法.
我可能会遗漏一些东西,但正如我所看到的,我的选择是:
Base64_encode 文件并在JSON响应中提供我还需要记住,其中一些文件需要私有,只有在成功验证后才能使用.
我还mod_xsendfile简要地看了一下实现,并想知道这是否是我应该考虑的路线.
我有一个使用多个连接的查询:
public function scopePurchased($query, $userId)
{
return $query
->join('products','characters.id','=','products.productable_id')
->join('bundle_product','bundle_product.product_id','=','products.id')
->join('bundles','bundles.id','=','bundle_product.bundle_id')
->join('purchases','purchases.bundle_id','=','bundles.id')
->join('users','purchases.user_id','=','users.id')
->whereNull('purchases.deleted_at')
->where('purchases.refunded', false)
->where('products.productable_type', '=', get_class($this))
->where('users.id','=',$userId)
->groupBy('characters.id')
->orderBy('characters.title', 'ASC');
}
Run Code Online (Sandbox Code Playgroud)
我想从这个查询中检索一个ID数组,以便在另一个范围内使用,这样:
$query->purchased($userID)->lists('id')
Run Code Online (Sandbox Code Playgroud)
我最初的想法是使用列表('id')抱怨对ID的模糊查询.
Column 'id' in field list is ambiguous
(
SQL: select `id` from `characters`
inner join `products` on `characters`.`id` = `products`.`productable_id`
inner join `bundle_product` on `bundle_product`.`product_id` = `products`.`id`
inner join `bundles` on `bundles`.`id` = `bundle_product`.`bundle_id`
inner join `purchases` on `purchases`.`bundle_id` = `bundles`.`id`
inner join `users` on `purchases`.`user_id` = `users`.`id`
where `characters`.`deleted_at` is null
and …Run Code Online (Sandbox Code Playgroud)