大米CMS官网论坛,大米站长联盟,大米站长之家,大米开发者社区

 找回密码
 注册大米会员

QQ登录

只需一步,快速开始

查看: 82|回复: 0
打印 上一主题 下一主题

在damishop企业版中使用laravel的Illuminate\Database

[复制链接]

501

主题

778

帖子

7664

积分

超级版主

Rank: 8Rank: 8

积分
7664

授权用户

跳转到指定楼层
楼主
发表于 2024-4-2 14:05:53 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 追影 于 2024-4-3 09:44 编辑
  1. $info = $this->capsule::table('product')->where('product_id',29)->first();
复制代码
模型或控制器中都可以直接使用$this->capsule




更多语法参考:https://laravel.com/docs/7.x/eloquent

查询方法
Illuminate\Database\Query\Builder 类包含如下公用方法:

查询

select($columns = ['*'])

selectSub($query, $as)

selectRaw($expression, array $bindings = [])

addSelect($column)

from($table, $as = null)

fromSub($query, $as)

fromRaw($expression, $bindings = [])

去重

distinct()

连接

join($table, $first, $operator = null, $second = null, $type = 'inner', $where = false)

joinSub($query, $as, $first, $operator = null, $second = null, $type = 'inner', $where = false)

joinWhere($table, $first, $operator, $second, $type = 'inner')

leftJoin($table, $first, $operator = null, $second = null)

leftJoinWhere($table, $first, $operator, $second)

leftJoinSub($query, $as, $first, $operator = null, $second = null)

rightJoin($table, $first, $operator = null, $second = null)

rightJoinWhere($table, $first, $operator, $second)

rightJoinSub($query, $as, $first, $operator = null, $second = null)

crossJoin($table, $first = null, $operator = null, $second = null)

crossJoinSub($query, $as)

查询条件

and

mergeWheres($wheres, $bindings)

where($column, $operator = null, $value = null, $boolean = 'and')

whereColumn($first, $operator = null, $second = null, $boolean = 'and')

whereRaw($sql, $bindings = [], $boolean = 'and')

whereIn($column, $values, $boolean = 'and', $not = false)

whereNotIn($column, $values, $boolean = 'and')

whereIntegerInRaw($column, $values, $boolean = 'and', $not = false)

whereIntegerNotInRaw($column, $values, $boolean = 'and')

whereNull($columns, $boolean = 'and', $not = false)

whereNotNull($columns, $boolean = 'and')

whereBetween($column, array $values, $boolean = 'and', $not = false)

whereBetweenColumns($column, array $values, $boolean = 'and', $not = false)

whereNotBetween($column, array $values, $boolean = 'and')

whereNotBetweenColumns($column, array $values, $boolean = 'and')

whereDate($column, $operator, $value = null, $boolean = 'and')

whereTime($column, $operator, $value = null, $boolean = 'and')

whereDay($column, $operator, $value = null, $boolean = 'and')

whereYear($column, $operator, $value = null, $boolean = 'and')

whereMonth($column, $operator, $value = null, $boolean = 'and')

addWhereExistsQuery(self $query, $boolean = 'and', $not = false)

whereRowValues($columns, $operator, $values, $boolean = 'and')

addDateBasedWhere($type, $column, $operator, $value, $boolean = 'and')

whereNested(Closure $callback, $boolean = 'and')

forNestedWhere()

addNestedWhereQuery($query, $boolean = 'and')

whereExists(Closure $callback, $boolean = 'and', $not = false)

whereNotExists(Closure $callback, $boolean = 'and')

whereJsonContains($column, $value, $boolean = 'and', $not = false)

whereJsonDoesntContain($column, $value, $boolean = 'and')

whereJsonLength($column, $operator, $value = null, $boolean = 'and')

or

orWhere($column, $operator = null, $value = null)

orWhereColumn($first, $operator = null, $second = null)

orWhereRaw($sql, $bindings = [])

orWhereIn($column, $values)

orWhereNotIn($column, $values)

orWhereIntegerInRaw($column, $values)

orWhereIntegerNotInRaw($column, $values)

orWhereNull($column)

orWhereBetween($column, array $values)

orWhereBetweenColumns($column, array $values)

orWhereNotBetween($column, array $values)

orWhereNotBetweenColumns($column, array $values)

orWhereNotNull($column)

orWhereDate($column, $operator, $value = null)

orWhereTime($column, $operator, $value = null)

orWhereDay($column, $operator, $value = null)

orWhereMonth($column, $operator, $value = null)

orWhereYear($column, $operator, $value = null)

orWhereExists(Closure $callback, $not = false)

orWhereNotExists(Closure $callback)

orWhereRowValues($columns, $operator, $values)

orWhereJsonContains($column, $value)

orWhereJsonDoesntContain($column, $value)

orWhereJsonLength($column, $operator, $value = null)

dynamicWhere($method, $parameters)

orWhereFullText($columns, $value, array $options = [])

分组

groupBy(...$groups)

groupByRaw($sql, array $bindings = [])

分组查询条件

having($column, $operator = null, $value = null, $boolean = 'and')

orHaving($column, $operator = null, $value = null)

havingBetween($column, array $values, $boolean = 'and', $not = false)

havingRaw($sql, array $bindings = [], $boolean = 'and')

orHavingRaw($sql, array $bindings = [])

排序

orderBy($column, $direction = 'asc')

orderByDesc($column)

latest($column = 'created_at') //时间倒叙

oldest($column = 'created_at')//等同于latest

inRandomOrder($seed = '')//随机排序

reorder($column = null, $direction = 'asc')//重新定义排序

分页

skip($value)//设置排序的便宜量的别名

offset($value)//设置偏移量

take($value)//同limit

limit($value)

forPage($page, $perPage = 15)

forPageBeforeId($perPage = 15, $lastId = 0, $column = 'id')

forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')

paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)

simplePaginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)

cursorPaginate($perPage = 15, $columns = ['*'], $cursorName = 'cursor', $cursor = null)

getCountForPagination($columns = ['*'])

联合

union($query, $all = false)

unionAll($query)

锁行

lock($value = true)

lockForUpdate()

sharedLock()

获取查询结果
find($id, $columns = ['*'])

get($columns = ['*']) //获取多行

value($column) //获取结果第一行

查看sql

toSql()

返回对象

cursor() //返回\Illuminate\Support\LazyCollection对象

pluck($column, $key = null)//返回\Illuminate\Support\Collection对象

implode($column, $glue = '')//等同于pluck

结果处理

exists()//确定当前查询是否有数据

doesntExist()//等同于exists

existsOr(Closure $callback)//没结果执行回调

doesntExistOr(Closure $callback)//等同于existsOr

聚合

count($columns = '*')

min($column)

max($column)

sum($column)

avg($column)

average($column)//等同于avg

numericAggregate($function, $columns = ['*'])

添加

insert(array $values)

insertOrIgnore(array $values)

insertGetId(array $values, $sequence = null)

insertUsing(array $columns, $query)

修改

update(array $values)

updateFrom(array $values)

updateOrInsert(array $attributes, array $values = [])

upsert(array $values, $uniqueBy, $update = null)

increment($column, $amount = 1, array $extra = [])//加定量值

decrement($column, $amount = 1, array $extra = [])//减定量值

delete($id = null)//删除

truncate()//清空表

newQuery()//获取\Illuminate\Database\Query\Builder对象

forSubQuery()//等同于newQuery

raw($value)//创建原始表达式


clone() //返回克隆查询对象

cloneWithout(array $properties)//返回克隆查询对象不包括给定属性

cloneWithoutBindings(array $except)//返回克隆查询对象 不包括给定绑定

dump()//框架自带输出函数 包含此方法的框架外调用会失败 但是可以自己实现

dd()//框架自带输出函数 包含此方法的框架外调用会失败 但是可以自己实现

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册大米会员

本版积分规则

QQ|小黑屋|大米CMS社区 ( 蜀ICP备11002200号-2广告联系:广告联系 

Powered by 大米CMS

© 2010-2020 大米CMS Inc.

快速回复 返回顶部 返回列表