首页
时事
归档
壁纸
更多
留言
关于
邻里
Search
1
使用必应Bing每日图片做网站背景(自动)
2,987 阅读
2
vue的输入值校验规则整理
1,662 阅读
3
VUE `ERR_CONNECTION_TIMED_OUT`的解决办法
1,629 阅读
4
好站推荐-https://wangchujiang.com/linux-command/
1,598 阅读
5
微信支付开发前准备(小程序、公众号、App、H5)
1,582 阅读
文章
图说
代码
吐槽
登录
Search
标签搜索
Linux
laravel
windows
TYPO3
php
shell脚本
git
微信
好站
vue
第三方登录
centos
linxu
centos7
thinkPHP
微信支付
api
MySQL
桌面
必应首图
Beer
累计撰写
114
篇文章
累计收到
22
条评论
首页
栏目
文章
图说
代码
吐槽
页面
时事
归档
壁纸
留言
关于
邻里
搜索到
6
篇与
laravel
的结果
2022-01-20
Laravel避免重复的查询判断
常用查询方案if ($request->type) { $query = $query->where('type', $request->type); } if ($request->wave) { $query = $query->where('wave', $request->wave); } if ($request->spu) { $query = $query->where('spu','like', "%".$request->spu."%"); } if ($request->sku) { $query = $query->where('sku','like', "%".$request->sku."%"); }优化查询方案foreach(['type', 'wave'] as $where){ if ($request->{$where}) { $query = $query->where($where, $request->{$where}); } } foreach(['spu', 'sku'] as $where){ if ($request->{$where}) { $query = $query->where($where, 'like',"%".$request->{$where}."%"); } }
2022年01月20日
734 阅读
0 评论
0 点赞
2022-01-20
Laravel修改.env配置文件
要修改的数据$data=[ 'BAN_STATUS'=>'false', 'PASSPORT_CLIENT'=>1, ];修改方法public function updateEnv(array $data) { $envPath = base_path() . DIRECTORY_SEPARATOR . '.env'; $contentArray = collect(file($envPath, FILE_IGNORE_NEW_LINES)); $contentArray->transform(function ($item) use ($data){ foreach ($data as $key => $value){ if(str_contains($item, $key)){ return $key . '=' . $value; } } return $item; }); $content = implode("\n", $contentArray->toArray()); \File::put($envPath, $content); }
2022年01月20日
619 阅读
0 评论
0 点赞
2021-11-09
基于Pear Admin与Laravel的后台管理系统
安装获取项目代码cd web部署目录 git clone https://gitee.com/pear-admin/Pear-Admin-Laravel.git chmod -R 755 ./Pear-Admin-Laravel cd ./Pear-Admin-Laravel composer update创建数据库mysql -uroot -p #输入密码 create database pear_admin_laravel配置数据库cp .env.example .env #配置.env里的数据库连接信息初始化数据php artisan key:generate #初始化key php artisan storage:link #软连文件存储目录 chmod -R 755 storage/ #文件存储目录权限 php artisan migrate --step #执行数据迁移 php artisan db:seed #写入初始化数据初始化完成后浏览器打开项目地址 https://www.domain.com/admin 登录初始化登录用户名:admin 密码:password可视化日志管理路由 https://www.domain.com/log-viewer务必在登录成功后修改密码其他Vhost-Apache配置<VirtualHost *:80> DocumentRoot "/var/www/html/Pear-Admin-Laravel/public" ServerName www.domain.com ErrorLog "logs/site1-error.log" CustomLog "logs/site1-access.log" common <Directory "/var/www/html/HBAdmin/public"> Options FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>Vhost-Nginx配置server { listen 80; server_name www.domain.com; root /var/www/html/Pear-Admin-Laravel/public; index index.html index.htm index.php; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } location ~ .php$ { try_files $uri =404; root /var/www/html/Pear-Admin-Laravel/public; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi.conf; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }redis安装cd ~ wget https://download.redis.io/releases/redis-6.2.5.tar.gz tar xzf redis-6.2.5.tar.gz cd redis-6.2.5 make make install PREFIX=/usr/local/redis cd /usr/local/redis/bin/ ll cp ~/redis-6.2.5/redis.conf ./ vim redis.conf #找到daemonize no 改为daemonize yes ./redis-server redis.conf #后台启动redis ps aux|grep redis #查看redis进程
2021年11月09日
943 阅读
0 评论
0 点赞
2021-09-04
Laravel 常用命令收集
创建项目laravel new blog || composer create-project --prefer-dist laravel/laravel blog安装组件composer install刷新组件composer update删除组件composer remove chensuilong/toastr composer dump-autoload查看artisan命令php artisan php artisan list启动PHP的Web服务php artisan serve查看某个帮助命令php artisan help make:model php artisan make:model User --migration 创建模型并创建新迁移查看laravel版本php artisan --version使用 PHP 内置的开发服务器启动应用php artisan serve生成一个随机的 key,并自动更新到 app/config/app.php 的 key 键值对(刚安装好需要做这一步)php artisan key:generate开启Auth用户功能(开启后需要执行迁移才生效)php artisan make:auth开启维护模式和关闭维护模式(显示503)php artisan down php artisan up进入tinker工具php artisan tinker列出所有的路由php artisan route:list生成路由缓存以及移除缓存路由文件php artisan route:cache php artisan route:clear重新生成签名php artisan passport:install自动生成Laravel密钥php artisan key:generateAuth 系统php artisan make:auth创建控制器php artisan make:controller StudentController创建Rest风格资源控制器(带有index、create、store、edit、update、destroy、show方法)php artisan make:controller PhotoController --resource创建模型php artisan make:model Student php artisan make:model User --migration //创建模型并创建新迁移创建新建表的迁移和修改表的迁移php artisan make:migration create_users_table --create=students //创建students表 php artisan make:migration add_votes_to_users_table --table=students//给students表增加votes字段执行迁移php artisan migrate php artisan migrate:rollback //回滚最新一次迁移创建模型的时候同时生成新建表的迁移php artisan make:model Student -m回滚上一次的迁移php artisan migrate:rollback回滚所有迁移php artisan migrate:reset php artisan migrate:refresh //更新表结构创建填充php artisan make:seeder StudentTableSeeder执行单个填充php artisan db:seed --class=StudentTableSeeder执行所有填充php artisan db:seed创建中间件(app/Http/Middleware 下)php artisan make:middleware Activity创建队列(数据库)的表迁移(需要执行迁移才生效)php artisan queue:table创建队列类(app/jobs下):php artisan make:job SendEmail创建请求类(app/Http/Requests下)php artisan make:request CreateArticleRequest php artisan:显示详细的命令行帮助信息,同 php artisan list php artisan –help:显示帮助命令的使用格式,同 php artisan help php artisan –version:显示当前使用的 Laravel 版本 php artisan changes:列出当前版本相对于上一版本的主要变化 php artisan down:将站点设为维护状态 php artisan up:将站点设回可访问状态 php artisan optimize:优化应用程序性能,生成自动加载文件,且产生聚合编译文件 bootstrap/compiled.php php artisan dump-autoload:重新生成框架的自动加载文件,相当于 optimize 的再操作 php artisan clear-compiled:清除编译生成的文件,相当于 optimize 的反操作 php artisan migrate:执行数据迁移 php artisan routes:列出当前应用全部的路由规则 php artisan serve:使用 PHP 内置的开发服务器启动应用 【要求 PHP 版本在 5.4 或以上】 php artisan tinker:进入与当前应用环境绑定的 REPL 环境,相当于 Rails 框架的 rails console 命令 php artisan workbench 组织名/包名:这将在应用根目录产生一个名为 workbench 的文件夹,然后按 组织名/包名 的形式生成一个符合 Composer 标准的包结构,并自动安装必要的依赖【需要首先完善好 app/config/workbench.php 文件的内容】 php artisan cache:clear:清除应用程序缓存 php artisan command:make 命令名:在 app/commands 目录下生成一个名为 命令名.php 的自定义命令文件 php artisan controller:make 控制器名:在 app/controllers 目录下生成一个名为 控制器名.php 的控制器文件 php artisan db:seed:对数据库填充种子数据,以用于测试 php artisan key:generate:生成一个随机的 key,并自动更新到 app/config/app.ph 的 key 键值对 php artisan migrate:install:初始化迁移数据表 php artisan migrate:make 迁移名:这将在 app/database/migrations 目录下生成一个名为 时间+迁移名.php 的数据迁移文件,并自动执行一次 php artisan dump-autoload 命令 php artisan migrate:refresh:重置并重新执行所有的数据迁移 php artisan migrate:reset:回滚所有的数据迁移 php artisan migrate:rollback:回滚最近一次数据迁移 php artisan session:table:生成一个用于 session 的数据迁移文件
2021年09月04日
767 阅读
0 评论
0 点赞
2021-05-25
Laravel 数据迁移字段类型&字段长度综合表
Laravel 数据迁移字段类型&字段长度综合表数值类型命令大小描述范围用途最大存储单位$table->tinyInteger('votes');1 字节相当于 TINYINT(-128,127)小整数值127b$table->tinyIncrements('id');1 字节相当于 自动递增 UNSIGNED TINYINT(0,255)小整数值255b$table->unsignedTinyInteger('votes');1 字节相当于 不递增 UNSIGNED TINYINT(0,255)小整数值255b$table->smallInteger('votes');2 字节相当于 SMALLINT(-32 768,32 767)大整数值31.99kb$table->unsignedSmallInteger('votes');2 字节相当于 不递增 UNSIGNED SMALLINT(0,65 535)大整数值63.99kb$table->mediumInteger('votes');3 字节相当于 MEDIUMINT(-8 388 608,8 388 607)大整数值 $table->unsignedMediumInteger('votes');3 字节相当于 Unsigned MEDIUMINT(0,16 777 215)大整数值 $table->integer('votes');4 字节相当于 INTEGER(-2 147 483 648,2 147 483 647)大整数值 $table->increments('id');4 字节递增的 ID (主键),相当于「UNSIGNED INTEGER」(0,4 294 967 295)大整数值 $table->bigInteger('votes');8 字节相当于 BIGINT(-9 233 372 036 854 775 808,9 223 372 036 854 775 807)极大整数值 $table->unsignedBigInteger('votes');8 字节相当于 UNSIGNED BIGINT(0,18 446 744 073 709 551 615)极大整数值 $table->float('amount', 8, 2);4 字节相当于带有精度与基数 FLOAT(-3.402 823 466 E+38,-1.175 494 351 E-38),0,(1.175 494 351 E-38,3.402 823 466 351 E+38)单精度浮点数值 $table->double('column', 8, 2);8 字节相当于带有精度与基数 DOUBLE(-1.797 693 134 862 315 7 E+308,-2.225 073 858 507 201 4 E-308),0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E+308)双精度浮点数值 $table->decimal('amount', 8, 2);对DECIMAL(M,D)相当于带有精度与基数 DECIMAL依赖于M和D的值小数值 字符串类型类型大小描述用途$table->char('name', 4);0-255字节相当于带有长度的 CHAR定长字符串$table->string('name', 100);0-65535 字节相当于带长度的 VARCHAR变长字符串TINYBLOB0-255字节 不超过 255 个字符的二进制字符串TINYTEXT0-255字节 短文本字符串$table->binary('data');0-65 535字节相当于 BLOB二进制形式的长文本数据$table->text('description');0-65 535字节相当于 TEXT长文本数据MEDIUMBLOB0-16 777 215字节 二进制形式的中等长度文本数据$table->mediumText('description');0-16 777 215字节相当于 MEDIUMTEXT中等长度文本数据LONGBLOB0-4 294 967 295字节 二进制形式的极大文本数据$table->longText('description');0-4 294 967 295字节相当于 LONGTEXT极大文本数据日期和时间类型命令大小描述范围格式用途$table->date('created_at');3字节相当于 DATE1000-01-01/9999-12-31YYYY-MM-DD日期值$table->time('sunrise');3字节相当于 TIME'-838:59:59'/'838:59:59'HH:MM:SS时间值或持续时间$table->year('birth_year');1字节相当于 YEAR1901/2155YYYY年份值$table->dateTime('created_at');8字节相当于 DATE1000-01-01 00:00:00/9999-12-31 23:59:59YYYY-MM-DD HH:MM:SS混合日期和时间值$table->timestamp('added_on');4字节相当于 TIMESTAMP1970-01-01 00:00:00/2038 结束时间是第 2147483647 秒,北京时间 2038-1-19 11:14:07,格林尼治时间 2038年1月19日 凌晨 03:14:07YYYYMMDD HHMMSS混合日期和时间值,时间戳//================================================================================= /* 表引擎 */ $table->engine = 'InnoDB'; /* 类型 */ // - 数字 $table->bigInteger('id'); $table->integer('id'); $table->mediumInteger('id'); $table->smallInteger('id'); $table->tinyInteger('id'); $table->decimal('balance', 15, 8); $table->float('balance'); $table->double('balance', 15, 8); $table->real('balance'); // - 时间 $table->date('created_at'); $table->dateTime('created_at'); $table->timeStamp('created_at'); $table->time('sunrise'); // - 字符串 $table->char('name', 4); // 等同于 VARCHAR $table->string('name'); // 等同于 VARCHAR(100) $table->string('name', 100); $table->text('description'); $table->mediumText('description'); $table->longText('description'); // 等同于 BLOB $table->binary('data'); $table->enum('choices', ['foo', 'bar']); $table->boolean('confirmed'); // - 不经常用的 $table->json('options'); // 等同于数据库中的 JSON 类型 $table->jsonb('options'); // 等同于数据库中的 JSONB 类型 $table->uuid('id'); // 等同于数据库的UUID // 自增ID,类型为 bigint $table->bigIncrements('id'); // 自增ID,类型为 int $table->increments('id'); // 添加一个 INTEGER类型的 taggable_id 列和一个 STRING类型的 taggable_type列 $table->morphs('taggable'); // 和 timestamps() 一样,但允许 NULL 值 $table->nullableTimestamps('created_at'); // 添加一个 'remember_token' 列:VARCHAR(100) NULL $table->rememberToken(); // 添加 'created_at' 和 'updated_at' $table->timeStamps(); // 新增一个 'deleted_at' 列,用于 '软删除' $table->softDeletes(); /* 列修改器 */ ->first(); // 将列置于表第一个列(仅限于MYSQL) ->after('列名'); // 将列置于某一列后(仅限于MYSQL) ->nullable(); // 允许列为NULL ->defalut($value); // 指定列默认值 ->unsigned(); // 设置整型列为 UNSIGNED /* 修改列 需安装 doctrine/dbal,composer require doctrine/dbal */ // change() - 修改列 $table->string('name', 30)->nullable()->change(); // renameColumn() - 重命名列 $table->renameColumn('name', 'title'); /* 删除列 需安装 doctrine/dbal,composer require doctrine/dbal */ // 删除单个列 $table->dropColumn('name'); // 删除多个列 $table->dropColumn(['name', 'age']); /* 创建索引 * 每种索引,都有3种方式: * 一个string参数 * 一个array参数 - 组合索引 * 2个参数 - 允许自定义索引名 * 注意: * laravel自动分配的索引名: * 表名_列名_索引类型:users_mobile_unique // users表的mobile字段为unique 索引 */ $table->primary('id'); // 主键索引 $table->primary(['first', 'last']); // 混合索引(这个不太清楚) $table->primary('first', 'first_primary_index']); // 自定义索引名 $table->unique('mobile'); // 唯一索引 $table->index('state'); // 普通索引 /* 删除索引 */ $table->dropPrimary('索引名') $table->dropUnique('索引名') $table->dropIndex('索引名') /* 外键约束 * 注意: * laravel自动分配的外键名: * 表名_列名_foreign:posts_user_id_foreign // posts表的user_id字段添加foreign */ // 添加外键,当前表的user_id,外键关联users表的id列 $table->foreign('user_id')->references('id')->on('users'); // 约束 'on delete' 和 'on update' 时,才关联外键 $table->foreign('user_id')->references('id')->on('users')->onDelete; // 删除外键 $table->dropForeign('posts_user_id_foreign');
2021年05月25日
844 阅读
0 评论
0 点赞
2021-02-07
Laravel php artisan 自动生成Model+Migrate+Controller 命令大全
Laravel php artisan 自动生成Model+Migrate+Controller 命令大全php artisan 命令是Laravel框架自带的命令,方便用户快速创建、查看对应的模块参数等。一、常用的命令:命令解释php artisan list 查看php artisan所有命令php artisan --help查看php artisan的用法php artisan help admin:make查看php artisan admin:make的用法php artisan admin:make --help查看php artisan admin:make的用法创建控制器php artisan make:controller OrderController创建Rest风格资源控制器(带有index、create、store、edit、update、destroy、show方法)php artisan make:controller OrderController --resource创建模型php artisan make:model Student创建新建表的迁移和修改表的迁移php artisan make:migration create_orders_table --create=orders //创建订单表ordersphp artisan make:migration add_tags_to_orders_table --table=orders//给orders表增加tags字段执行迁移php artisan migrate创建模型的时候同时生成新建表的迁移+控制器+路由php artisan make:model Order -m -c -r回滚上一次的迁移php artisan migrate:rollback回滚所有迁移php artisan migrate:reset创建填充php artisan make:seeder OrderTableSeeder执行单个填充php artisan db:seed --class=OrderTableSeeder执行所有填充php artisan db:seed创建中间件(app/Http/Middleware 下)php artisan make:middleware Activity创建队列(数据库)的表迁移(需要执行迁移才生效)php artisan queue:table创建队列类(app/jobs下):php artisan make:job SendEmail创建请求类(app/Http/Requests下)php artisan make:request CreateArticleRequest二、通常一个laravel项目的后台管理系统搭建流程,如下下载Laravel框架,安装Laravel-admin后台管理框架,进行基础的数据库连接配置,上传配置,https/http访问方式等Linux服务器下面,进入项目的根目录,可以用php artisan make命令创建模型+数据迁移+控制器。用php artisan admin:make 创建后台的控制器,可以写脚本批量创建。之后根据业务逻辑,编写控制器内容。为后台的控制器创建对于的路由,可以写脚本批量创建。登录Laravel-admin后台系统,设置对应的菜单。三、Laravel Artisan 命令大全Available commands:命令中文Englishclear-compiled删除已编译的类文件Remove the compiled class filedown将应用程序置于维护模式Put the application into maintenance modedump-server启动转储服务器以收集转储信息。Start the dump server to collect dump information.env显示当前的框架环境Display the current framework environmenthelp显示命令的帮助Displays help for a commandinspire---Display an inspiring quotelist列出命令Lists commandsmigrate运行数据库迁移Run the database migrationsoptimize缓存框架引导程序文件Cache the framework bootstrap filespreset为应用程序交换前端脚手架Swap the front-end scaffolding for the applicationserve在 PHP 开发服务器上提供应用程序Serve the application on the PHP development servertinker与您的应用程序互动Interact with your applicationup使应用程序退出维护模式Bring the application out of maintenance modeapp命令中文Englishapp:name设置应用程序命名空间Set the application namespaceauth命令中文Englishauth:clear-resets刷新过期的密码重置令牌Flush expired password reset tokenscache命令中文Englishcache:clear刷新应用程序缓存Flush the application cachecache:forget从缓存中删除项目Remove an item from the cachecache:table为缓存数据库表创建迁移Create a migration for the cache database tableconfig命令中文Englishconfig:cache创建缓存文件以加快配置速度Create a cache file for faster configuration loadingconfig:clear删除配置缓存文件Remove the configuration cache filedb命令中文Englishdb:seed填充数据库Seed the database with recordsevent命令中文Englishevent:generate根据注册生成缺少的事件和侦听器Generate the missing events and listeners based on registrationkey命令中文Englishkey:generate生成应用程序 keySet the application keylang命令中文Englishlang:publish将语言文件发布到资源目录publish language files to resources directory.make命令中文Englishmake:auth---Scaffold basic login and registration views and routesmake:channel创建一个新的 channel 类Create a new channel classmake:command创建一个新的 Artisan 命令Create a new Artisan commandmake:controller创建一个新的控制器类Create a new controller classmake:event---创建一个新的 event 类make:exception创建一个新的自定义异常类Create a new custom exception classmake:factory创建一个新的模型工厂Create a new model factorymake:job创建一个新的工作类Create a new job classmake:listener创建一个新的事件监听器类Create a new event listener classmake:mail创建一个新的电子邮件类Create a new email classmake:middleware创建一个新的中间件类Create a new middleware classmake:migration创建一个新的迁移文件Create a new migration filemake:model创建一个新的 Eloquent 模型类Create a new Eloquent model classmake:notification创建一个新的通知类Create a new notification classmake:observer创建一个新的观察者类Create a new observer classmake:policy创建一个新的策略类Create a new policy classmake:provider创建一个新的服务提供者类Create a new service provider classmake:request创建一个新的表单请求类Create a new form request classmake:resource创建一个新资源Create a new resourcemake:rule创建新的验证规则Create a new validation rulemake:scaffold代码生成器 — Laravel 5.x Scaffold GeneratorCreate a laralib scaffoldmake:seeder创建一个新的 seeder 类Create a new seeder classmake:test创建一个新的测试类Create a new test classmigrate命令中文Englishmigrate:fresh删除所有表并重新运行所有迁移Drop all tables and re-run all migrationsmigrate:install创建迁移存储库Create the migration repositorymigrate:refresh重置并重新运行所有迁移Reset and re-run all migrationsmigrate:reset回滚所有数据库迁移Rollback all database migrationsmigrate:rollback回滚上次数据库迁移Rollback the last database migrationmigrate:status显示每次迁移的状态Show the status of each migrationnotifications命令中文Englishnotifications:table为通知表创建迁移Create a migration for the notifications tableoptimize命令中文Englishoptimize:clear删除缓存的引导程序文件Remove the cached bootstrap filespackage命令中文Englishpackage:discover重建缓存的包清单Rebuild the cached package manifestqueue命令中文Englishqueue:failed列出所有 failed 队列工作List all of the failed queue jobsqueue:failed-table为 failed 队列工作数据库表创建迁移Create a migration for the failed queue jobs database tablequeue:flush刷新所有 failed 队列工作Flush all of the failed queue jobsqueue:forget删除 failed 队列工作Delete a failed queue jobqueue:listen监听一个给定的队列Listen to a given queuequeue:restart在当前工作之后重新启动队列工作器守护程序Restart queue worker daemons after their current jobqueue:retry重试 failed 队列作业Retry a failed queue jobqueue:table为队列工作数据库表创建迁移Create a migration for the queue jobs database tablequeue:work开始将队列上的工作作为守护程序处理Start processing jobs on the queue as a daemonroute命令中文Englishroute:cache创建路由缓存文件以加快路由注册速度Create a route cache file for faster route registrationroute:clear删除路由缓存文件Remove the route cache fileroute:list列出所有注册的路由List all registered routesschedule命令中文Englishschedule:run运行预定的命令Run the scheduled commandssession命令中文Englishsession:table为会话数据库表创建迁移Create a migration for the session database tablestorage命令中文Englishstorage:link创建从 “公共 / 存储” 到 “存储 / 应用 / 公共” 的符号链接Create a symbolic link from "public/storage" to "storage/app/public"vendor命令中文Englishvendor:publish从供应商包中发布任何可发布的资产Publish any publishable assets from vendor packagesview命令中文Englishview:cache编译所有应用程序的 Blade 模板Compile all of the application's Blade templatesview:clear清除所有编译的视图文件Clear all compiled view files
2021年02月07日
835 阅读
0 评论
0 点赞