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’t 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’s 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’t 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’t want to breaking change any request and response, previously I wrote feature test case in phpunit, but here are several problems: It’s a mock data for testing flow, it’s simular but not real. I need to prepare and mock many situations to assert it. I don’t want to bet and take a risk for refactoring. So I make a new functions: Comparsion, it’s simple but useful....

April 3, 2022 · 4 min · Yish

如何更快速學習

這邊歸納出我目前學會或認知到的"如何更快速更有效率的學習總結"。 學習路線和方向 一旦學習有了方向跟路線,按部就班的學習和在流程內,那麼學習到的概念就會是務實的。 目標 假如想要找一門程式語言找工作,但不知道學習哪個項目好,不如打開你最想去的公司的技能需求,一但有了明確的目標學習起來就會有方向了。 獨具慧眼 在挑選學習項目時,其實最重要的不是工具的好壞,而是效率跟性價比問題,所以在做選擇時必須衡量過時間成本和投入資源,取得一個適合自己的最佳解。 弱連結 很多時候當下學習的項目看起來沒什麼幫助,但實際上都會是相關聯的,只要是在同個領域必然存在著弱連結,不妨先建立一個 indexing 的概念,日後有應用時就藉由弱連結找到解法。 回想 在快速變化的產業與時代,很多時候面向的是快速與廣度問題,不需要每個東西都牢牢記住,但能夠快速回想曾經有看過,如同上個原則,這個時代講究的是廣度,深度是指你所擅長的事情,而廣度是支持你強大的關鍵。 回饋 徵求良好的回饋和想法,不是每個想法都是好的,但試著去詢問和找尋回饋讓自己變得更好。 筆記 這邊說的筆記不是指要做的多精美和多有規範,相反我提倡快速筆記,跳躍筆記,並且閱讀自己的筆記去做連結學習,注意筆記是輔助理解問題,而不是最終的產品。

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’s 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’s 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