Larravel ` Http:: withUrlParameters ` Usage Author: Chuwen Time: 2023-07-18 Classification: Laravel , PHP comment ##Before use When calling the HTTP API, you will find that many APIs adopt the * REST API * style, for example: * /admin/api/2023-07/products/{product_id}.json * /admin/api/2023-01/orders/{order_id}.json * /admin/api/2023-01/orders/{order_id}/fulfillments/{fulfillment_id}.json * ... It is easy to find that they all have one thing in common. They are replaced with corresponding values by variables wrapped in curly braces ('{var_name}', '{order_id}'). Usually, we may do this: ```php $http = \Illuminate\Support\Facades\Http::baseUrl(' https://example.com '); $order_id = 123456789; $fulfillment_id = 9889894445; $orderUrl = sprintf('/admin/api/2023-07/orders/%d.json', $product_id); $fulfillmentUrl = sprintf('/admin/api/2023-01/orders/%d/fulfillments/%d.json', $order_id, $fulfillment_id); $order = $http->get($orderUrl); $fulfillment = $http->get($fulfillmentUrl); ``` However, it will be tedious to splice URIs like this ##After use - ` Http:: withUrlParameters` ```php $http = \Illuminate\Support\Facades\Http::baseUrl(' https://example.com ') ->withUrlParameters([ 'order_id' => 123456789, 'fulfillment_id' => 9889894445 ]); //For example, you need to use the above URL parameter: order_id //You only need to fill in {order_id} in the URL //Automatically replace when requested $orderUrl = '/admin/api/2023-07/orders/{order_id}.json'; $fulfillmentUrl = '/admin/api/2023-01/orders/{orders_id}/fulfillments/{fulfillment_id}.json'; $order = $http->get($orderUrl); $fulfillment = $http->get($fulfillmentUrl); ``` You will find it convenient to use, and you don't need to use "sprintf" to splice URLs
Resolve the error in running the php command: dyld: Library not loaded:/usr/local/opt/icu4c/lib/libicuio.72.dylib Author: Chuwen Time: 2023-07-07 Classification: Programming tools comment ##Solution Just reinstall 'icu4c' ```shell brew reinstall icu4c ``` --- Solution source: https://gist.github.com/berkedel/d1fc6d13651c16002f64653096d1fded?permalink_comment_id=3676196#gistcomment -3676196
PHPStorm command line tool support - add hyperf command Author: Chuwen Time: 2023-07-07 Classification: Magic Skills comment ##Operation steps 1. Open the PHP Storm setting 2. Select * * Tools | Command Line Tool Support * * 3. Select * * Command Line Tools * * (command line tools support) 4. Click "+" to add ! []( https://cdn.nowtime.cc/2023/07/07/3007301678.png ) 5. Select as shown in the figure ! []( https://cdn.nowtime.cc/2023/07/07/2083503232.png ) 6. Tool settings ** * Alias * * can be entered as required, such as' hyper 'and' h '. Here I select' h 'as an alias for convenience ** * Script Path * * Enter the relative path of the hyperf script ` bin/hyperf.php` ! []( https://cdn.nowtime.cc/2023/07/07/3110325419.png ) 7. Click OK and apply settings ! []( https://cdn.nowtime.cc/2023/07/07/211859290.png ) ##Using 1. Double click the Ctrl key to call up the "Run anything" window ! [Double click the Ctrl key to call up the "Run anything" window]( https://cdn.nowtime.cc/2023/07/07/3703838478.png ) 2. Enter relevant commands such as' h d ', and then command association will be performed ! []( https://cdn.nowtime.cc/2023/07/07/2930141368.png ) 3. Select a command and press Enter to run ! []( https://cdn.nowtime.cc/2023/07/07/3925011794.png )
Brew Set Proxy Author: Chuwen Time: 2023-07-04 Classification: macOS comment ## 1. Find the location of 'brew' The general path is in '/usr/local/bin/brew', please record it, and you need to use it later ```shell ➜ ~ which brew /usr/local/bin/brew ``` ## 2. Move the 'brew' command location ```shell mv /usr/local/bin/brew /usr/local/bin/brew_orig ``` ## 3. Create a new file such as'. proxy 'to set proxy Execute the command 'vim~/. proxy. sh'. The file content is: >The following proxy server addresses are adjusted according to your actual situation ```shell #!/ bin/bash export https_proxy= http://127.0.0.1:7890 export http_proxy= http://127.0.0.1:7890 export all_proxy=socks5://127.0.0.1:7890 ``` ## 4. New '/usr/local/bin/brew' file Execute Command ` vim/usr/local/bin/brew` The contents of the document are: ```shell #!/ bin/bash source ~/.proxy.sh /usr/local/bin/brew_orig "$@" ``` And give executable permission ` chmod+x/usr/local/bin/brew` ## 5. Test Use ```shell ➜ ~ cat $(which brew) #!/ bin/bash source ~/.proxy.sh /usr/local/bin/brew_orig "$@" ➜ ~ brew --version Homebrew 4.0.26 Homebrew/homebrew-core (git revision 3112e690293; last commit 2022-07-12) Homebrew/homebrew-cask (git revision 2ae6e86efe; last commit 2023-02-16) ```
How to use Laravel Mixin Author: Chuwen Time: 2023-06-29 Classification: PHP comment #Contents <!-- TOC --> *[Directory] (# Directory) * [1. Create Directory] (# 1-Create Directory) * [2. Extend Corresponding Class] (# 2 - Extend Corresponding Class) * [3. Mixin macro](#3-mixin-macro) * [3. Use] (# 3-Use) <!-- TOC --> ## 1. Create Directory ```shell mkdir -p app/Macros ``` ## 2. Expand corresponding class For example, if you want to extend 'Arr', you can create a file like 'ArrMacros. php' The contents are as follows: ```php <? php namespace App\Macros; use Illuminate\Support\Arr; class ArrMacros { /** *Append URL query parameters * * @return \Closure */ public function appendUrlQuery(): \Closure { /** *@ param string $url link can be relative/absolute link * @param array $queryData * @see \App\Macros\ArrMacros::appendUrlQuery() * * @return string */ return function (string $url, array $queryData) { if (!blank($queryData)) { if (str_contains($url, '?')) { $url .= "&"; } else { $url .= "?"; } } return $url . Arr::query($queryData); }; } } ``` ## 3. Mixin macro Add the following code to the 'boot' method of 'app/Provider/AppServiceProvider. php' ```php \Illuminate\Support\Arr::mixin(new \App\Macros\ArrMacros()); ``` ## 3. use ```php echo \Illuminate\Support\Arr::appendUrlQuery('/test', [ 'ref' => 'nowtime_cc' ]); //Output result:/test? ref=nowtime_cc ``` ## 4. other If you still use https://github.com/barryvdh/laravel-ide-helper You can also use 'php artisan ide helper: generate' to generate corresponding comments, and there will be syntax prompt in PHP Storm ! []( https://cdn.nowtime.cc/2023/06/29/1457489303.png )