Modify Package by Composer

In newer laravel, we are use many ways to instead of 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 - Manual, 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

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

Laravel Assert Middleware

In my case, I would like to assert the middleware what I through, Here is my soulution. // TestCase or what you like to put in. public function assertMiddleware($middleware, $request = null, ...$args) { // To be sure it's implemented handle method. if (! method_exists($middleware, 'handle')) { throw new BadMethodCallException(); } // Does it need to customize request? $request = $request?:new Request(); // instanced and called from handle. $instance = App::make($middleware)->handle($request, function($request) { return new JsonResponse($request); }, ....

March 27, 2022 路 1 min 路 Yish