小编Sam*_*ikh的帖子

如何在 Laravel 中的 REST API 中使用或创建分页?

我想在 Laravel 的 Rest API 中创建一个分页。我想要分页,假设数据库中有总共 30 个类别,并且我想在每页中显示 10 个项目,因此总页面将为 3,每页将显示 10 个项目。

我已经使用了paginate()方法,但它只显示给定编号的项目,我在脚本下面使用了它,但它没有提供我提到的输出。

$getCategories = Category::paginate();
$listCat = array();
    foreach($getCategories as $val){
        $cateName['id'] = $val->id;
        $cateName['name'] = $val->name;
        $cateName['description'] = $val->description;
        $cateName['image'] = url('/').'/public/assets/images/category/'.$val->image;
        $listCat[] = $cateName;
    }
    
    if(!empty($listCat)){
        $respons['status'] = 'true';
        $respons['message'] = 'Categories list';
        $respons['data list']=$listCat;
    }else{
       $respons['status'] = 'false';
       $respons['message'] = 'Category is not found.'; 
    }
return Response::json($respons,200);
Run Code Online (Sandbox Code Playgroud)

有人告诉我如何在 Rest Api 中使用分页吗?

我得到的输出像..

在此输入图像描述

php rest laravel laravel-5

7
推荐指数
1
解决办法
4万
查看次数

Woocommerce 如何按产品 SKU 显示产品

我的一位客户想要按产品显示所有 woocommerce 产品SKU

通常我使用以下代码来展示产品。

$postArg = array('post_type'=>'product',
                            'post_status'=>'publish',
                            'posts_per_page'=>-1,
                            'orderby'=>'data',
                            'order'=>'DESC',

                    );

            $queryGetFiles = get_posts($postArg);
Run Code Online (Sandbox Code Playgroud)

但是现在我的客户想SKU在前面按产品显示所有产品。

像这样的 SKU 1041-14, 1041-12, 1041-16 ,1041,2001,3501

所有产品都有不同的 sku 值和没有"-"字符的显示

有谁知道我该怎么做?

php wordpress woocommerce

4
推荐指数
1
解决办法
2364
查看次数

只有管​​理员允许访问 wp-admin 并登录吗?

我想这样做,只有管理员(角色)允许使用 wp-admin 登录,而不是任何其他角色,其他用途(如编辑,作者)是从前端登录,并且工作正常,但我希望只有管理员可以通过 wp 登录-行政。

我已经使用终极会员插件进行前端登录。 终极插件链接

我还使用了下面的代码来访问 wp-admin 仅适用于管理员(角色),但它不起作用。

<?php
function restrict_admin(){
//if not administrator, kill WordPress execution and provide a message
   if( !current_user_can('administrator') ) {
        wp_die( __('You are not allowed to access this part of the site') );
    }
}
add_action( 'admin_init', 'restrict_admin', 1 );
?>
Run Code Online (Sandbox Code Playgroud)

php wordpress

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

仅显示父级自定义分类名称?

我想仅显示父类别名称而不是子类别名称,并且未在任何产品或帖子中使用,我只需要列出父自定义类别。

我尝试过get_termswp_list_categories函数,但它也显示子项

这是我的代码。

<?php 
  require_once('connection.php');
  $taxonomy     = 'product_cat';
  $orderby      = 'parent';
  $show_count   = 0;      // 1 for yes, 0 for no
  $pad_counts   = 0;      // 1 for yes, 0 for no
  $hierarchical = 0;      // 1 for yes, 0 for no
  $title        = '';
  $empty        = 0;

  $args = array(
    'taxonomy'     => $taxonomy,
    'orderby'      => $orderby,
    'show_count'   => $show_count,
    'pad_counts'   => $pad_counts,
    'childless'              => false,
    'child_of'               => 0,
    'title_li'     => $title,
    'hide_empty'   => $empty,
    'hierarchical'=>1
    //'hierarchical=0&depth=1' …
Run Code Online (Sandbox Code Playgroud)

php wordpress

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

SELECT DISTINCT在一列上,在mysql中有多列

我必须显示选择多列的结果,但仅在一列上显示不同,我也使用了以下查询,并在下面的链接中进行了引用。

查询一。

select category , offer_id, store_image from  `tbl_coupan_offer` where
`offer_id` in (Select max(`offer_id`) FROM  `tbl_coupan_offer` group by `category`)  
Run Code Online (Sandbox Code Playgroud)

以上查询返回所有记录,包括重复记录

我只想显示不重复的类别

以下是图片

在此处输入图片说明

在图像上,您可以看到重复的旅行和配件

第二查询

SELECT DISTINCT `category`,`offer_id`,`store_image` FROM `tbl_coupan_offer` 
Run Code Online (Sandbox Code Playgroud)

我还引用了此链接,从一列中不同的行中选择所有列

php mysql sql

2
推荐指数
1
解决办法
3787
查看次数

标签 统计

php ×5

wordpress ×3

laravel ×1

laravel-5 ×1

mysql ×1

rest ×1

sql ×1

woocommerce ×1