当前位置: 首页 > wzjs >正文

合肥做网站联系方式开发新客户的十大渠道

合肥做网站联系方式,开发新客户的十大渠道,建设商务网站需要哪些步骤,福建省网站建设方案书1、事件需要运行 php artisan queue:work 2、数据库对象关联 1对1 hasOne 1对多 hasMany 1依赖多 belongsTo 多依赖多 belongsToMany 3、 关联查询 with 关联统计 withCount 统计时指定字段名。 如: withCount([cardHolderOrders as order_count]); 4、 // 一次查询&…


1、事件需要运行
php artisan queue:work

2、数据库对象关联
1对1 hasOne
1对多 hasMany
1依赖多  belongsTo
多依赖多 belongsToMany 


3、
关联查询
with

关联统计
withCount

统计时指定字段名。

如:
withCount(['cardHolderOrders as order_count']);


4、
// 一次查询,判断昵称、手机号、会员ID 是否重复
if (!empty($id)) {
    $checkName = AdminModel::query()->where('id', '<>', $id);
} else {
    $checkName = AdminModel::query();
}

$checkName->where(function ($query) use ($nickname, $mobile, $memberId) {
    $query->when($memberId , function ($q) use($memberId) {
        $q->orWhere('member_id', $memberId);
    })->when($nickname , function ($q) use($nickname) {
        $q->orWhere('nick_name', $nickname);
    })->when($mobile , function ($q) use($mobile) {
        $q->orWhere('mobile', $mobile);
    });
});

查出结果后,还需要再依次判断,是哪一个字段重复了。
例如:

if($checkName->first()){
    $user = $checkName->first();

    // 判断昵称
    if($user['nick_name'] == $nickname) {
        throw new ApiException("昵称已存在");
    }

    // 判断手机号
    else if($user['mobile'] == $mobile) {
        throw new ApiException("手机号已存在");
    }

    // 判断成员关系
    elseif(!empty($memberId) && $user['member_id'] == $memberId) {
        throw new ApiException("已绑定其他用户");
    }
}


5、
怎样无侵入的限制用户针对某个数据表的访问权限。

#新建全局作用域,放到namespace对应文件夹里。

<?php
namespace App\Scopes;

/**
 * 用于 无侵入式过滤 权限。
*/

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;

class DynamicShopFilterScope implements Scope
{
    protected $searchColumn;
    protected $ids;

    public function __construct($searchColumn, $ids)
    {
        $this->searchColumn = $searchColumn;
        $this->ids = $ids;
    }

    public function apply(Builder $builder, Model $model)
    {
        if (!empty($this->ids)) {
            $builder->whereIn($this->searchColumn, $this->ids);
        }
    }
}

#新建中间件,放到namespace对应文件夹里。

<?php
namespace App\Http\Middleware;

/**
 * 用于控制哪些功能,需要 后台用户的权限。
 */

use App\Scopes\DynamicShopFilterScope;
use Closure;

class ApplyShopFilter
{
    public function handle($request, Closure $next)
    {
        $ids = request()->input('tokenInfo')['ids'];

        // 添加用于过滤的全局作用域
        // 某列表
        YourModel::addGlobalScope(
            new DynamicShopFilterScope('id', $ids)
        );

        // 某列表
        YouTwoModel::addGlobalScope(
            new DynamicShopFilterScope('shop_id', $ids)
        );
        
        return $next($request);
    }
}

在需要限制的功能的路由中,加上中间件。
这样,对应功能中,对应Model的所有操作就会加上限制了。


 

http://www.dtcms.com/wzjs/151062.html

相关文章:

  • 青浦区建设和管理委员会网站seo方法
  • 网站建设方案及预算扬州网站推广公司
  • wordpress 点赞按钮seo优化要做什么
  • 上海市建设工程安全质量监督总站网站海外网站推广优化专员
  • 南京行业门户网站网络推广自学
  • 网站建设服务采购方案模板下载厦门seo大佬
  • 外部链接链轮的建设对于网站提产品宣传推广方案
  • 网站建设的切片是什么河北搜索引擎优化
  • 网站seo公司企业网站seo排名优化
  • 怎么进成品网站后台模板建站公司
  • 如何申请域名做网站合肥百度seo排名
  • 白石桥做网站公司网站改进建议有哪些
  • 石家庄又封了网站搜索优化价格
  • 网站站点结构图怎么做网站查找工具
  • 网站地图案例国际新闻最新消息今天
  • 怎么建设自己个人网站seo综合查询系统
  • 中国摄影网站十大排名身边的网络营销案例
  • 博兴网站建设百度在线客服系统
  • 做兼职写小说网站系统优化大师
  • 甘肃省城乡住房建设厅网站免费隐私网站推广app
  • 摄影网站下载花关键词排名系统
  • 初学ssm做的网站网站建设找哪家公司好
  • 能用于制作网页的软件排名优化哪家好
  • 中国循环经济网站开发与设计100个成功营销案例
  • 淘客网站建设视频2021最火关键词
  • 国家建设部网站倪虹qq群引流推广平台
  • 哪个建设网站好深圳外贸网站制作
  • 网站建设设计未来前景b站推广入口在哪
  • 公司设计网站需要注意哪些百度快照查询
  • 亚马逊 怎么做国外网站搭建一个app平台要多少钱