1、安装php-ext扩展 lib_version未被定义
(1) 重装libzip
#卸载当前libzip
yum remove libzip
#下载高版本libzip
https://github.com/nih-at/libzip/archive/rel-1-5-2.tar.gz
#需要cmake3.0版本才能编译
yum install cmake3
#解压
tar -xzvf rel-1-5-2.tar.gz -C /usr/local
cd /usr/local/rel-1-5-2
mkdir build
cd build
cmake3 ..
make
make install
(2) 重新安装zip扩展
cd /usr/local/src
wget http://pecl.php.net/get/zip-1.13.5.tgz
tar -zxvf zip-1.13.5.tgz
cd zip-1.13.5
/opt/remi/php70/root/usr/bin/phpize #根据自己安装的路径变更
./configure --with-php-config=/opt/remi/php70/root/usr/bin/php-config #根据自己安装的路径变更
make
make test
make install
#php.ini
extension=zip.so
#重启php-fpm
service php-fpm restart
laravel问题
jwt
使用laravel+jwtoken的时候报错
Argument 3 passed to Lcobucci\JWT\Signer\Hmac::doVerify() must be an instance of Lcobucci\JWT\Signer\Key, null given
php artisan jwt:secret
jwt找不到key值所以报错
laravel Eloquent Orm
全局作用域
- 全局范围能为给定模型的所有查询添加约束
<?php
namespace App\Models\Scopes;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
class WorkingScope implements Scope
{
/**
* 将范围应用于给定的 Eloquent 查询生成器
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function apply(Builder $builder, Model $model)
{
return $builder->where('is_working', 1);
}
}
- 应用全局作用域
要将全局作用域分配给模型,需要重写给定模型的 boot 方法并使用 addGlobalScope 方法:
model类
/**
* 全局作用域
*
* @return void
*/
protected static function boot()
{
parent::boot();
static::addGlobalScope(new WorkingScope());
}
- 删除作用域
public function talentList(array $columns)
{
return Staff::withoutGlobalScopes(([WorkingScope::class]))
->where('is_working', 0)->get($columns);
}
orm 关联
model
public function departmentRelation()
{
return $this->hasOne(Department::class, 'id', 'dept_id');
}
public function userRelation()
{
return $this->hasOne(User::class, 'id', 'user_id');
}
public function staffRoleRelation()
{
return $this->hasMany(StaffRoleRelation::class, 'staff_id', 'id');
}
public function staffDeptRelation()
{
return $this->hasMany(StaffDeptRelation::class, 'staff_id', 'id');
}
public function listPageByRole($role_id, $page=1, $pageSize=10)
{
$res = $this->model->join('staff_role_relation', function ($query) use ($role_id) {
$query->on('staff_role_relation.staff_id', '=', 'staff.id');
$query->where('staff_role_relation.role_id', $role_id);
})
->with(['userRelation' => function ($query) {
$query->select(['id', 'real_name', 'mobile', 'gender']);
}])
->with(['departmentRelation' => function ($query) {
$query->select(['id', 'name']);
}])
->with(['staffDeptRelation' => function ($query) {
$query->select(['id', 'staff_id', 'dept_id']);
}]);
return $res->select(
'staff_role_relation.id',
'staff.user_id',
'staff.work_number',
'staff.dept_id',
)->paginate($pageSize, ['*'], 'page', $page);
}
mac上传文件
scp -p 22 ./data.sql root@远程ip地址:/root //把data.sql文件上传到 远程服务器的 /root目录下
laravel上传文件建立软连接无效
进入容器建立软连接
php artisan storage:link