![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
PHP
_Elias
这个作者很懒,什么都没留下…
展开
-
laravel设置ORM关联关系(分表相关)
注意适用场景:仅需要获取到某个记录对应的数据,不适用于需要进行with内部进行where判断的场景,其他分表场景建议使用数据库中间件处理示例:tests与records表1对多关系1:records模型如下<?phpnamespace App;use Illuminate\Database\Eloquent\Model;class Record extends Mo...原创 2020-03-20 17:56:37 · 996 阅读 · 0 评论 -
laravel临时暴露隐藏属性/隐藏显示属性
$user = User::where('id', 1)->get();$user->makeVisible('attribute')->toArray();$user->makeHidden('attribute')->toArray();原创 2020-03-04 16:36:42 · 1082 阅读 · 0 评论 -
strtotime函数在使用-1 month, +1 month, next month避免自动规范化出现日期出错
直接使用strtotime("-1 month"),会在大小月的时候出现错误,例如12月31的时候得到的是12月1号而不是11月30增加参数就可以避免规范化导致的出错strtotime("last day of -1 month")strtotime("first day of -1 month")...原创 2019-12-31 09:58:06 · 605 阅读 · 0 评论 -
laravel获取json参数
$request->getContent();原创 2018-12-08 10:25:31 · 4018 阅读 · 0 评论 -
laravel orm随机排序
->inRandomOrder()原创 2018-12-08 10:26:06 · 1408 阅读 · 0 评论 -
laravel计数统计
$data = $res->with('book') ->withCount(['records as all','records as correct' => function ($query) { $query->where('records.result', '1');}]) ->orderBy('created_at','desc'...原创 2018-12-08 10:25:56 · 706 阅读 · 0 评论 -
laravel存在条件的时候为orm加入条件判断
isset($method) && !empty($method) && $orm->where('test_method', $method);原创 2018-12-08 10:25:43 · 1576 阅读 · 0 评论 -
日期及时间处理包 Carbon 在 Laravel 中的简单使用
在编写 PHP 应用时经常需要处理日期和时间,这篇文章带你了解一下 Carbon – 继承自 PHP DateTime 类的 API 扩展,它使得处理日期和时间更加简单。Laravel 中默认使用的时间处理类就是 Carbon。1 安装通过 Composer 来安装 Carbon:composer require nesbot/carbon PS:由于 Laravel 项目已默...转载 2018-12-08 10:24:57 · 882 阅读 · 0 评论 -
PHP数组计数
array_count_values($arr)原创 2018-12-20 15:24:18 · 447 阅读 · 0 评论 -
laravel中使用laravel-excel进行导出
composer require "maatwebsite/excel:~2.1.0"在config/app.php中注册服务提供者到providers数组Maatwebsite\Excel\ExcelServiceProvider::class,在config/app.php中注册门面到aliases数组'Excel' => Maatwebsite\Excel\Fac...原创 2018-12-28 10:31:13 · 1627 阅读 · 0 评论 -
laravel-excel进行导入
前端<input id="fileSelect" name="fileSelect" ref="inputer" type="file"/><button class="btn btn-danger" style="margin-bottom: 10px;" @click="fileupdate">导入&原创 2018-12-28 13:59:18 · 580 阅读 · 0 评论 -
laravel获取固定条数数据
->take(30)原创 2018-12-08 10:25:22 · 3093 阅读 · 1 评论 -
laravel筛选满足具备某个字段信息的数据(去掉字段值为null的数据)
$word_lists = Wordlist::whereHas( 'book' , function ($query) use($book_id) { $query->where('id',$book_id); })->with(['book:id,bookname']) ->get();前面whereHas为条件筛选,后面一个wi...原创 2018-11-01 14:46:12 · 4000 阅读 · 0 评论 -
jquery的ajax切换同步异步
$.ajaxSettings.async = false;$.get(url,data,function(msg){},"text");$.ajaxSettings.async = true;原创 2018-06-14 13:35:52 · 380 阅读 · 0 评论 -
中文使用json_encode不转码的方法
添加第二个参数:JSON_UNESCAPED_UNICODE原创 2018-06-08 15:33:31 · 11733 阅读 · 0 评论 -
TP的关联模型查询笔记(备忘)
//进行关联定义belongsTo设置(一对一关系)public function img(){ //关联模型名,外键名,当前模型主键名 return $this->belongsTo("ImageModel","img_id","id");} //进行关联定义hasMany设置(一对多关系)public function items(){ //关联...原创 2018-08-03 16:02:50 · 1356 阅读 · 0 评论 -
文件操作,一行一行读取,中间以空格隔开
$filename = 'toefl.txt';$handle = fopen ($filename, "r"); while (!feof ($handle)){ $buffer = fgets($handle, 4096); $username = trim($buffer); $record=str_replace("\t","_",$username)...原创 2018-09-17 16:35:07 · 2229 阅读 · 0 评论 -
php文件下载
!!!!不要用ajax请求下载,ajax没有数据流形式的数据,需要使用的话要模拟表单请求前端使用window.location.href直接请求页面即可public function process(Vtiger_Request $request){ $mul_class_id = $request->get('productinstanceid'); $sql...原创 2018-09-19 16:02:33 · 290 阅读 · 0 评论 -
PHP正则匹配中文
$str = "php编程";if (preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$str)) {print("该字符串全部是中文");} else {print("该字符串不全部是中文");}转载 2018-09-20 16:33:06 · 91 阅读 · 0 评论 -
将自然数转成中文
public static function numtochr($num,$mode=true) { $char = array("零","一","二","三","四","五","六","七","八","九"); $dw = array("","十",&原创 2018-11-01 13:58:48 · 189 阅读 · 0 评论 -
正则匹配所有合法的HTML标签
</?[^>]+>原创 2018-11-01 14:18:02 · 3287 阅读 · 0 评论 -
laravel框架中引入全局错误码以及相关报错信息
project\config\errorcode.php<?php/** * Created by PhpStorm. * User: DELL * Date: 2018/9/6 * Time: 10:28 */return [ /* |-----------------------------------------------------------...原创 2018-11-01 14:39:15 · 897 阅读 · 0 评论 -
laravel判断orm查询结果是否为空
$orm->isEmpty()原创 2018-11-01 14:40:52 · 2337 阅读 · 0 评论 -
FastAdmin的CURD生成功能使用整理
FastAdmin——基于ThinkPHP5+Bootstrap的极速后台开发框架官方文档地址https://doc.fastadmin.net/docs/index.html 一键生成CURD 准备工作 常用命令红色框框起来的第一个是二表关联,第二种是多表关联(注意是A表关联B表,A表关联C表型的多表关联)第三种关联在后面会写(A表关联B表,B表关联C表) 执行后会生成4类文件applicati...原创 2018-05-08 22:14:52 · 15603 阅读 · 3 评论