Modify Package by Composer

In newer laravel, we are use many ways to instead of https://github.com/Zizaco/entrust package doing works, but previous project still use it. for now, the project needs to upgrade to newer laravel, the package doesn鈥檛 support newer laravel, we can upgrade to suit our project by composer. Documentation Changes to * signature in composer.json "require": { "zizaco/entrust": "*" } cloning package For this project I put into /packages/ in application, app/ packages/ entrust/ repositories "repositories": [ { "type": "path", "url": "packages/entrust" } ], Finally you do composer update, you can customize or update the package by yourself, running the testing cases and more....

April 6, 2022 路 1 min 路 Yish

Trait Instead of the Other Trait Method

use AuditableWithOrder; use \OwenIt\Auditing\Auditable { AuditableWithOrder::transformAudit insteadof \OwenIt\Auditing\Auditable; } How to overwrite the trait on self or the others trait? It鈥檚 about vanilla PHP, here is documentation PHP: Traits - Manualhttps://www.php.net/manual/en/language.oop5.traits.php, here is an example. trait Taggable { public function slug() { return Str::slug($this->slug, '-'); } } For now, I don鈥檛 want to make a string slugging for slug, I would like changing to snake, in the past, I would like to do following:...

April 3, 2022 路 3 min 路 Yish

Comparsion Apis in Laravel

In my cases, I want to refactor the codebase but I don鈥檛 want to breaking change any request and response, previously I wrote feature test case in phpunit, but here are several problems: It鈥檚 a mock data for testing flow, it鈥檚 simular but not real. I need to prepare and mock many situations to assert it. I don鈥檛 want to bet and take a risk for refactoring. So I make a new functions: Comparsion, it鈥檚 simple but useful....

April 3, 2022 路 4 min 路 Yish

濡備綍鏇村揩閫熷缈

閫欓倞姝哥磵鍑烘垜鐩墠瀛告渻鎴栬獚鐭ュ埌鐨"濡備綍鏇村揩閫熸洿鏈夋晥鐜囩殑瀛哥繏绺界祼"銆 瀛哥繏璺窔鍜屾柟鍚 涓鏃﹀缈掓湁浜嗘柟鍚戣窡璺窔锛屾寜閮ㄥ氨鐝殑瀛哥繏鍜屽湪娴佺▼鍏э紝閭i杭瀛哥繏鍒扮殑姒傚康灏辨渻鏄嫏瀵︾殑銆 鐩 鍋囧鎯宠鎵句竴闁绋嬪紡瑾炶█鎵惧伐浣滐紝浣嗕笉鐭ラ亾瀛哥繏鍝嬮爡鐩ソ锛屼笉濡傛墦闁嬩綘鏈鎯冲幓鐨勫叕鍙哥殑鎶鑳介渶姹傦紝涓浣嗘湁浜嗘槑纰虹殑鐩瀛哥繏璧蜂締灏辨渻鏈夋柟鍚戜簡銆 鐛ㄥ叿鎱х溂 鍦ㄦ寫閬稿缈掗爡鐩檪锛屽叾瀵︽渶閲嶈鐨勪笉鏄伐鍏风殑濂藉锛岃屾槸鏁堢巼璺熸у児姣斿晱椤岋紝鎵浠ュ湪鍋氶伕鎿囨檪蹇呴爤琛¢噺閬庢檪闁撴垚鏈拰鎶曞叆璩囨簮锛屽彇寰椾竴鍊嬮仼鍚堣嚜宸辩殑鏈浣宠В銆 寮遍g祼 寰堝鏅傚欑暥涓嬪缈掔殑闋呯洰鐪嬭捣渚嗘矑浠楹煎公鍔╋紝浣嗗闅涗笂閮芥渻鏄浉闂滆伅鐨勶紝鍙鏄湪鍚屽嬮牁鍩熷繀鐒跺瓨鍦ㄨ憲寮遍g祼锛屼笉濡ㄥ厛寤虹珛涓鍊 indexing 鐨勬蹇碉紝鏃ュ緦鏈夋噳鐢ㄦ檪灏辫棄鐢卞急閫g祼鎵惧埌瑙f硶銆 鍥炴兂 鍦ㄥ揩閫熻畩鍖栫殑鐢㈡キ鑸囨檪浠o紝寰堝鏅傚欓潰鍚戠殑鏄揩閫熻垏寤e害鍟忛锛屼笉闇瑕佹瘡鍊嬫澅瑗块兘鐗㈢墷瑷樹綇锛屼絾鑳藉蹇熷洖鎯虫浘缍撴湁鐪嬮亷锛屽鍚屼笂鍊嬪師鍓囷紝閫欏嬫檪浠h瑳绌剁殑鏄唬搴︼紝娣卞害鏄寚浣犳墍鎿呴暦鐨勪簨鎯咃紝鑰屽唬搴︽槸鏀寔浣犲挤澶х殑闂滈嵉銆 鍥為 寰垫眰鑹ソ鐨勫洖楗嬪拰鎯虫硶锛屼笉鏄瘡鍊嬫兂娉曢兘鏄ソ鐨勶紝浣嗚│钁楀幓瑭㈠晱鍜屾壘灏嬪洖楗嬭畵鑷繁璁婂緱鏇村ソ銆 绛嗚 閫欓倞瑾殑绛嗚涓嶆槸鎸囪鍋氱殑澶氱簿缇庡拰澶氭湁瑕忕瘎锛岀浉鍙嶆垜鎻愬″揩閫熺瓎瑷橈紝璺宠簫绛嗚锛屼甫涓旈柋璁鑷繁鐨勭瓎瑷樺幓鍋氶g祼瀛哥繏锛屾敞鎰忕瓎瑷樻槸杓斿姪鐞嗚В鍟忛锛岃屼笉鏄渶绲傜殑鐢㈠搧銆

April 2, 2022 路 1 min 路 Yish

Redis Backup Switching in laravel

In my situation, I face a problem with redis, our redis service(RDS) is unstable with unknown problem, but I need to solve consistency service and zero-downtime, so on my first solve problem that I do switch service in my application. Here is my thinking steps: Redis service needs to bind container by singlton Trying to connect Master redis, if it鈥檚 failed, rebinding second redis service. No middleware for now, it should be in service provider....

April 2, 2022 路 2 min 路 Yish

Define the Version in Laravel

This idea is inspiring from laravel codebase, web.php, it鈥檚 a useful and simple. // As you can see, it can be used to define the api or code version simplify. if (! defined('DEFAULT_VERSION')) { define('DEFAULT_VERSION', '9.x'); } if (! defined('SHOW_VAPOR')) { define('SHOW_VAPOR', random_int(1, 2) === 1); } // Also you can do something when definition was equaled. if (! defined('SHOW_PROMO')) { $int = random_int(1, 3); if ($int === 1) { define('SHOW_PROMO', 'FORGE'); } elseif ($int === 2) { define('SHOW_PROMO', 'VAPOR'); } elseif ($int === 3) { define('SHOW_PROMO', 'PARTNERS'); } }

April 2, 2022 路 1 min 路 Yish