本文整理汇总了PHP中app\models\Product::setFavourites方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::setFavourites方法的具体用法?PHP Product::setFavourites怎么用?PHP Product::setFavourites使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Product
的用法示例。
在下文中一共展示了Product::setFavourites方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
public function show($id)
{
$product = \App\Models\Product::query()->with(['seller' => function ($q) {
$q->select('id', 'username');
}, 'categories'])->find($id);
if ($userAuth = \Auth::user()) {
\App\Models\Product::setFavourites(collect([$product]), $userAuth);
}
return $product ?: $this->notFoundJson();
}
示例2: index
public function index(UserAuth $userAuth, $uid)
{
$seller = \App\Models\User::find($uid) ?: $this->notFoundJson();
$query = $seller->wares()->select(['id', 'title', 'subtitle', 'seller_id', 'price', 'stock_available', 'starts', 'ends', 'is_active', 'created_at', 'updated_at']);
$count = $query->count();
$items = $query->forPage(request('page', 1), request('limit', $this->pageLimit))->get();
if ($userAuth) {
$products = collect();
foreach ($items as $item) {
$products[] = $item->product;
}
\App\Models\Product::setFavourites($products, $userAuth);
}
if ($userAuth) {
\App\Models\Product::setFavourites($items, $userAuth);
}
return ["count" => $count, "limit" => request('limit', $this->pageLimit), "page" => request()->input('page', 1), "items" => $items];
}
示例3: index
public function index(UserAuth $userAuth, $uid)
{
$seller = \App\Models\User::find($uid) ?: $this->notFoundJson();
$query = $seller->sells()->with(['product' => function ($q) {
$q->select('id', 'title');
}, 'seller' => function ($q) {
$q->select('id', 'username');
}, 'buyer' => function ($q) {
$q->select('id', 'username');
}]);
$count = $query->count();
$items = $query->forPage(request('page', 1), request('limit', $this->pageLimit))->get();
if ($userAuth) {
$products = collect();
foreach ($items as $item) {
$products[] = $item->product;
}
\App\Models\Product::setFavourites($products, $userAuth);
}
return ["count" => $count, "limit" => request('limit', $this->pageLimit), "page" => request()->input('page', 1), "items" => $items];
}