问题描述
我正在使用以下方法访问api路由。它在某种程度上有效,但是href无效,并且在链接中同时给出了两个斜杠('/'&'')。而且该链接不起作用。
下面是ProductResource文件。
<?PHP
namespace App\Http\Resources\Product;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Request;
class ProductResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'name' => $this->product_name,'description' => $this->detail,'price' => $this->price,'stock' => $this->stock == 0 ? 'Out of stock' : $this->stock,'discount' => $this->discount,'discountedPrice' => $this->price-(( $this->discount / 100 ) * $this->price),'rating' => $this->reviews->count() > 0 ? round($this->reviews->sum('rating') / $this->reviews->count(),2) : 'Not rating yet ','href' => [
'review' => route('reviews.index',$this->id)
]
];
}
}
这是我的回报
http:\/\/127.0.0.1:8000\/api\/products\/51\/reviews
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)