Laravel之分页

  1. 获取数据集时使用paginate()方法。
  2. 视图文件中加载显示分页链接。

示例代码参考:

效果图:

Laravel中使用excel导入导出

使用composer安装库:composer require maatwebsite/excel

项目地址:https://github.com/Maatwebsite/Laravel-Excel

导入:

  1. 创建Import对象:php artisan make:import UsersImport
  2. 将导入的excel内容解析成数组:$excelContent = Excel::toArray(new UsersImport, $request->file('user_file'));

导出:

  1. 创建Export对象:php artisan make:export UsersExport
  2. 修改collection()方法,返回要导出的数据return collect($exportArrayData);
  3. 保存导出的excel文件:

【参考:https://docs.laravel-excel.com/3.1/exports/

Laravel使用提示

1。 为env文件生成secret: php artisan key:generate

2。启用oauth时,需要执行以下命令创建认证文件:

laravel解析excel文件中的日期字段

  1. 使用以下类库解析excel:https://github.com/Maatwebsite/Laravel-Excel
  2. 需要解析日期字段时,建议使用  PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($dateFromExcel) ,封装后的方法如下,

    【参考】

1.  https://github.com/Maatwebsite/Laravel-Excel;

2. https://github.com/Maatwebsite/Laravel-Excel/issues/1832#issuecomment-442572868

composer国内镜像源

使用方法:

修改项目根目录中的composer.json,修改或添加以下内容:

 

镜像源地址:

https://packagist.laravel-china.org/

安装swoole

若使用pecl或编译安装swoole时,出现如下类似错误,

则需要升级下gcc(达到5.0以上版本):

【摘自:】https://forum.phalconphp.com/discussion/17595/problem-with-compiled-phalcon-with-php-721

安装swoole时可能出现的错误

错误内容类似如下:

解决方式:

【摘自:】https://github.com/swoole/swoole-src/issues/2119

PS, 用 pecl install swoole 时,使用默认安装配置项比较容易成功

yum安装PHP7

The CentOS 7 official software repositories have PHP 5.4 which has reached the end of life and no longer actively maintained by the developers.

To keep up with the latest features and security updates, you need a newer (probably the latest) version of PHP on your CentOS 7 system.

For the purpose of this guide, we will be operating the system as root, if that is not the case for you, make use of the sudo command to acquire root privileges.

Installing PHP 7 on CentOS 7

1. To install PHP 7, you have to install and enable EPEL and Remi repository on your CentOS 7 system with the commands below.

2. Next, you need to install yum-utils, a collection of useful programs for managing yum repositories and packages. It has tools that basically extend yum’s default features.

It can be used for managing (enabling or disabling) yum repositories as well as packages without any manual configuration and so much more.

3. One of the programs provided by yum-utils is yum-config-manager, which you can use to enable Remirepository as the default repository for installing different PHP versions as shown.

If you want to install PHP 7.1PHP 7.2 or PHP 7.3 on CentOS 7, just enable it as shown.

4. Now install PHP 7 with all necessary modules with the command below.

Afterwards, double check the installed version of PHP on your system.

Check PHP Version in CentOS 7

Check PHP Version in CentOS 7

 

【原文:】https://www.tecmint.com/install-php-7-in-centos-7/