小编Mar*_*all的帖子

我应该如何从用PHP编写的RESTful api提供二进制文件(图像/音频)?

我正在计划一个RESTful API,我想知道在api中提供文件/文件包的最佳方法.

我可能会遗漏一些东西,但正如我所看到的,我的选择是:

  1. Base64_encode 文件并在JSON响应中提供
  2. 提供JSON响应中文件的链接.

我还需要记住,其中一些文件需要私有,只有在成功验证后才能使用.

我还mod_xsendfile简要地看了一下实现,并想知道这是否是我应该考虑的路线.

php rest json laravel laravel-4

5
推荐指数
1
解决办法
1285
查看次数

Laravel 4.2使用带有连接查询的lists()来说服

我有一个使用多个连接的查询:

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)

eloquent laravel-4

3
推荐指数
1
解决办法
3039
查看次数

标签 统计

laravel-4 ×2

eloquent ×1

json ×1

laravel ×1

php ×1

rest ×1