4月 11, 2023 - laravel    Laravel使用orm的chunk且有delete时删除不全已关闭评论

Laravel使用orm的chunk且有delete时删除不全

Laravel使用orm的chunk且有delete时会遇到删除不全的问题:

Image::where('property_id', 48)->chunk(2, function ($images) {

    foreach ($images as $image) {

        $image->delete();

    }

});

假如有5条数据,则运行后期望是全部删除,但实际会剩余2条数据.

应该使用chunkById这种方式:

Image::where('property_id', 48)->chunkById(2, fu[......]

Read more

3月 20, 2023 - laravel    Laravel6 export customize data to excel file.已关闭评论

Laravel6 export customize data to excel file.

使用composer包工具:maatwebsite/excel

"maatwebsite/excel": "^3.1

步骤:

1:先定义一个export的Object

<?php

namespace App\Imports;

use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Imports\HeadingRowFormatter;

HeadingRowFormatter::default('none');

class UsersImport implements FromA[......]

Read more

3月 3, 2023 - php开发    php解析url的参数已关闭评论

php解析url的参数

想要解析一个url的参数.可以采用parse_url+parse_str的结合来完成:示例:

$a = 'https://staging.ivi.cn?expires_in=2023-03-04 11:01:42&jwt_token=eyJ0eXAiOiJKV1QiLCJhb';
parse_str(parse_url($a)['query'], $result_arr);

$result_arr结果如下:

array:2 [
"expires_in" => "2023-03-04 11:01:42"
 "jwt_token" => "eyJ0eXAiOiJKV[......]

Read more

页面:«1...11121314151617...45»