xxxxxxxxxx
return ProductOptionsModel::query()->where('product_id', $product_id)->with(['product_option_value', 'option'])->get()
->map(function ($option) {
return [
'id' => $option['id'],
'get_lang_type' => app()->getLocale(),
'option_id' => $option['option_id'],
'name' => AdminService::trans($option->option->name),
'type' => $option['type'],
'required' => $option['required'],
'product_option_value' => $option->product_option_value->map(function ($value) {
if ($value->other_product_id && $value->other_product_id !== 0 && ProductModel::query()->where('status', '!=', 0)
->where('id', '=', $value->other_product_id)->exists()) {
return [
'id' => $value->id,
'name' => AdminService::trans($value->option_value->name),
'image' => $value->option_value->image,
'product_id' => $value->product_id,
'other_product_id' => $value->other_product_id ?? 0,
'option_id' => $value->option_id,
'product_option_id' => $value->product_option_id,
'option_value_id' => $value->option_value_id,
'quantity' => $value->quantity,
'subtract' => $value->subtract,
'price' => $value->price,
'price_prefix' => $value->price_prefix,
'points' => $value->points,
'points_prefix' => $value->points_prefix,
'weight' => $value->weight,
'weight_prefix' => $value->weight_prefix,
];
}
})->filter()->toArray(),
];
});
xxxxxxxxxx
$filteredCollection = $po_items->filter(function ($value) { return !is_null($value); });
dd($filteredCollection);
xxxxxxxxxx
$filteredUsers = $users->filter(function ($user, $key) {
return $user->role != null;
});
xxxxxxxxxx
return ProductOptionsModel::query()->where('product_id', $product_id)->with(['product_option_value', 'option'])->get()
->map(function ($option) {
return [
'id' => $option['id'],
'get_lang_type' => app()->getLocale(),
'option_id' => $option['option_id'],
'name' => AdminService::trans($option->option->name),
'type' => $option['type'],
'required' => $option['required'],
'product_option_value' => $option->product_option_value->map(function ($value) {
if ($value->other_product_id && $value->other_product_id !== 0 && ProductModel::query()->where('status', '!=', 0)
->where('id', '=', $value->other_product_id)->exists()) {
return [
'id' => $value->id,
'name' => AdminService::trans($value->option_value->name),
'image' => $value->option_value->image,
'product_id' => $value->product_id,
'other_product_id' => $value->other_product_id ?? 0,
'option_id' => $value->option_id,
'product_option_id' => $value->product_option_id,
'option_value_id' => $value->option_value_id,
'quantity' => $value->quantity,
'subtract' => $value->subtract,
'price' => $value->price,
'price_prefix' => $value->price_prefix,
'points' => $value->points,
'points_prefix' => $value->points_prefix,
'weight' => $value->weight,
'weight_prefix' => $value->weight_prefix,
];
}
})->whereNotNull()->toArray(),
];
});
xxxxxxxxxx
// This works
$messages = Message::where(•'•read_at is null•'•)->get();
// Won’t work - will return 0 messages
$messages = Message::all();
$unread_messages = $messages->where(•'•read_at is null•'•)->count();
// Will work
$unread_messages = $messages->where(•'•read_at•'•, •''•)->count();