1.导出分页模版
php artisan vendor:publish --tag=laravel-pagination
2.导出后生成模版目录/resources/views/vendor/pagination/default.blade.php
3.复制自定义模版到/resources/views/paginate/default.blade.php目录下
$test->render('paginate.default'); // 设置选择分页
1.导出分页模版
php artisan vendor:publish --tag=laravel-pagination
2.导出后生成模版目录/resources/views/vendor/pagination/default.blade.php
3.复制自定义模版到/resources/views/paginate/default.blade.php目录下
$test->render('paginate.default'); // 设置选择分页
mysql安装成功后可以看到已经存在mysql、information_schema和test这个几个数据库,information_schema库中有一个名为COLUMNS的表,这个表中记录了数据库中所有表的字段信息。知道这个表后,获取任意表的字段就只需要一条select语句即可。例如:
select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name';
上述的做法有一点问题,如果多个数据库中存在你想要查询的表名,那么查询的结果会包括全部的字段信息。通过DESC information_schema.COLUMNS可以看到该表中列名为TABLE_SCHEMA是记录数据库名,因此下面的写法更为严格
select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name' and table_schema = 'your_db_name';
取字段注释
Select COLUMN_NAME 列名, DATA_TYPE 字段类型, COLUMN_COMMENT 字段注释
from INFORMATION_SCHEMA.COLUMNS
Where table_name = 'companies'##表名
AND table_schema = 'testhuicard'##数据库名
AND column_name LIKE 'c_name'##字段名
1、新建文件,文件名任意:
app/Helpers/function.php
2、在composer.json 中 autoload 增加:
“autoload”:{
...
"files":[
"app/Helpers/function.php"
]
}
3、打开cmd 切换到项目目录 执行命令:
composer dump-auto
主要是方便快速写入代码,比如后端增删改查CRUD
1.创建命令文件
#php artisan make:command 命令文件名
php artisan make:command Validator
2.注册命令在/app/Console/Kernel.php中添加一下内容
protected $commands = [
\App\Console\Commands\Validator::class
];
3.编写命令步骤如下:
先在/app/Console/Commands/validator/下创建validator.stub和default_method.stub文件(目录名称建议命令一致,在自定义多个的情况下方便区分)
validator.stub : 逻辑层的主要内容,包含命名空间和类
<?php
namespace {{namespace}};
# 看个人情况确定是否包含继承文件和导入文件
use Illuminate\Support\Facades\Validator;
class {{class_name}} extends Validator
{
{{default_method}}
}
default_method.stub : 默认方法模板,根据--resource参数来确认是否写入logic.stub
public function index()
{
}
public function test()
{
}
相关Validator.php命令名称,参数和描述
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:validator {name} {--resource}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'create validator';
修改Validator.php命令文件中handle方法:列举如下
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
// 获取参数
$args = $this->arguments();
// 获取可选参数
$option = $this->option('resource');
// 处理组合参数
$args_name = $args['name'];
if (strstr($args['name'], '/')) {
$ex = explode('/', $args['name']);
$args_name = $ex[count($ex)-1];
$namespace_ext = '/' . substr($args['name'], 0, strrpos($args['name'], '/'));
}
$namespace_ext = $namespace_ext ?? '';
// 类名
// $class_name = $args_name . 'Validator';
$class_name = $args_name;
//文件名
$file_name = $class_name . '.php';
// 文件地址
$logic_file = app_path() . '/Validator' . $namespace_ext . '/' . $file_name;
// 命名空间
$namespace = 'App\Validator' . str_replace('/', '\\', $namespace_ext);
// 目录
$logic_path = dirname($logic_file);
// 获取模板,替换变量
$template = file_get_contents(dirname(__FILE__) . '/stubs/validator.stub');
$default_method = $option ? file_get_contents(dirname(__FILE__) . '/stubs/default_method.stub') : '';
$source = str_replace('{{namespace}}', $namespace, $template);
$source = str_replace('{{class_name}}', $class_name, $source);
$source = str_replace('{{default_method}}', $default_method, $source);
// 是否已存在相同文件
if (file_exists($logic_file)) {
$this->error('文件已存在');
exit;
}
// 创建
if (file_exists($logic_path) === false) {
if (mkdir($logic_path, 0777, true) === false) {
$this->error('目录' . $logic_path . '没有写入权限');
exit;
}
}
// 写入
if (!file_put_contents($logic_file, $source)) {
$this->error('创建失败!');
exit;
}
$this->info('创建成功!');
}
4.使用自定义命令:
#如果不需要默认方法,去掉--reource参数即可
#php artisan make:validator User --resource
php artisan make:validator User
mysql 8.0版本以后 默认使用 caching_sha2_password 身份验证机制 —— 从原来的 mysql_native_password 更改为 caching_sha2_password。客户端不支持新的加密方式。
修改用户的密码和加密方式
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
再刷新权限
flush privileges;