laravel之model
记录laravel 中model常用方法
1.keyBy()

指定数据的某个字段作为该条数据的key
2.like操作
$model->where('goods', 'like', '%test%');
3.In
self::select(\DB::raw("id,count(*) as total"))->whereIn('id', [1,2,3])->get()->toArray();
4)where 和 orWhere
select `id` from `user` wehre (email='xxx@xx.com' and password='123456') or (mobile='123456898' and password='123456'); model: User::select(['id'])
->where(function($query) use($username, $password) {
$query->where('password','=', $password)->where('email', '=', $username);
})
->orWhere(function($query) use($username, $password) {
$query->where('passowrd','=', $password)->where('mobile','=', $username);
})
->first();
select count(*) from suer where type=1 and valid_type=2 and(valid_en<3435454 or valid_begin > 434555);
model:
User::where('type', 1)->where('valid_type', '=', 2)->where(function($query){
$query->where('valid_end', '<', 4344545)->orWhere(function($query){
$query->where('valid_begin', '>', 14334353);
});
});
select count(*) from 'user’where 'valid_type = 2 or ('valid_type’ = 3 and ('valid_end`< 156073857e or "valid_begin`>1560738570));
model:
User::where(function($query){
$query->wehre('valid_type', 2);
})->orWhere(function($query){
$query->where('valid_type','=', 3)->where(function($query){
$query->where('valid_end', '<', 1243545)->orWhere(function($query){
$query->where('valid_begin', '>', 1343454);
});
});
})
})->first();
原生写法:
$model->whereRaw('name like ? or code like ?', [$keyword, $keyword])
laravel之model的更多相关文章
- Laravel创建Model
它已被用于CI框架.最近学习使用Laravel框架,要总结一些遇到的问题是一个创纪录,供以后调用.此外,我希望能够碰到同样的问题的朋友的帮助. 在Laravel数据库表是根据Laravel写好的程序去 ...
- 关于laravel框架Model返回的值为stdClass对象转换两种方法
一般情况下laravel模型层查询出来的数据是stdClass对象,无法直接当做数组进行视图展示,所以需要转换为数组格式. Model中查到的数据为 $data ,对它进行转化,转化为数组. 第一 ...
- laravel的model
1.创建模型 $ php artisan make:model Models/Issue 2.模型的白名单机制,用于赋值 class Issue extends Model { //指定表名 pr ...
- laravel添加model文件夹,需要改动的地方
首先,将app\User(等model文件),移入APP\modellists文件夹中,方便整理 第二,修改模型中命名空间和引用其他model的路径 第三,将文件夹app\admin中的控制器文件,全 ...
- laravel的model例子
5里面直接artisan建立model ./artisan make:model MyModel 找到MyModel,改成下面这样 <?php namespace App; use Illumi ...
- laravel中model类中好用的方法
public function field() { return $this->belongsTo(HrmAuthFieldsModel::class, 'filed_id', 'id'); } ...
- 2016 版 Laravel 系列入门教程(一)【最适合中国人的 Laravel 教程】
本教程示例代码见: https://github.com/johnlui/Learn-Laravel-5 在任何地方卡住,最快的办法就是去看示例代码. 本文基于 Laravel 5.2 版本,无奈 5 ...
- Laravel教程 五:MVC的基本流程
Laravel教程 五:MVC的基本流程 此文章为原创文章,未经同意,禁止转载. Controller 期间受到很多私事影响,终于还是要好好写写laravel的教程了. 上一篇我们说了数据库和Eloq ...
- Laravel 5 基础(七)- Eloquent (laravel 的ORM)
我们来生成第一个模型 php artisan make:model Article #输出 Model created successfully. Created Migration: 2015_03 ...
- laravel框架——学习笔记
routes.php文件创建路由参数由{}包起来,不需要$ Route::get('/stu/{as}','StuController@show'); 在相对应的Controller创建funcito ...
随机推荐
- 【YashanDB知识库】手动停止统计信息自动收集任务导致的性能变差
[问题分类]功能使用 [关键字]统计信息收集 [问题描述]UAT对外演示环境因统计信息收集任务引起数据库整理性能变慢无应急处理手段 [问题原因分析] ● DROP_JOB程序用于删除一个非执行状态下的 ...
- [python][selenium] Web UI自动化8种页面元素定位方式
关联文章:Web UI自动化页面切换iframe框架 简单的加个前置知识: 第一:webdriver.Chrome()这句话,通过WebDriver的构造方法,拿到浏览器驱动的对象,然后通过这个对象, ...
- Google Ads – UTM
介绍 UTM (Urchin tracking module) 的作用是帮助我们收集访客的来源渠道. 比如说, 用户是从 Google 广告来的, Youtube, 还是 Facebook 等等. 它 ...
- Vue Cli 创建项目在 GitHub 部署 history 路由模式
1.修改打包路径 在 vue.config.js 中添加 publicPath 配置,其中 teambition-vue 是你项目的 github 名字.否则会找不到资源. module.expo ...
- Android Qcom USB Driver学习(三)
usb hub区分端口 USB 子系统拓扑浅析 USB ID Database VendorID and ProductID usb usb1: New USB device found, idVen ...
- 【PyTorch】state_dict详解
这篇博客来自csdn,完全用于学习. Introduce 在pytorch中,torch.nn.Module模块中的state_dict变量存放训练过程中需要学习的权重和偏执系数,state_dict ...
- Java日期时间API系列23-----Jdk8中java.time包中的新的日期时间API类,获取准确开始时间00:00:00,获取准确结束时间23:59:59等
有时候,往往需要统计某个时间区间的销量等问题,这就需要准确的起始时间,获取准确开始时间00:00:00,获取准确结束时间23:59:59.下面增加了一一些方法,获取当天起始时间,昨天起始时间,当前月第 ...
- dotnet 冒泡排序
// See https://aka.ms/new-console-template for more information using ConsoleApp1; Console.WriteLine ...
- kotlin集合——>迭代器、区间与数列
1.迭代器 对于遍历集合元素,Kotlin 标准库支持 迭代器 的常用机制⸺对象可按顺序提供对元素的访问权限,而 不会暴露集合的底层结构.当需要逐个处理集合的所有元素(例如打印值或对其进行类似更新)时 ...
- python 打包 py 文件 为exe
使用 pyinstaller 来进行打包 pip install pyinstaller 可能需要全局 科学 代理上网 或者 修改 下载源地址 执行命令 图标path:C:\desktop\icon ...