本文整理匯總了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];
}