<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Laravel on seth-shi</title><link>https://sethix.com/tags/laravel/</link><description>Recent content in Laravel on seth-shi</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Tue, 07 Jan 2025 14:19:05 +0800</lastBuildDate><atom:link href="https://sethix.com/tags/laravel/index.xml" rel="self" type="application/rss+xml"/><item><title>Troubleshooting High Memory Usage in PHP Queue Service</title><link>https://sethix.com/posts/2025010714/</link><pubDate>Tue, 07 Jan 2025 14:19:05 +0800</pubDate><guid>https://sethix.com/posts/2025010714/</guid><description>The operations team reported recurring OOM (Out-Of-Memory) restarts in a container pod. Monitoring data showed periodic memory spikes: 1.png The service in question handles video composition via queue jobs. It uses shell_exec to invoke commands like ffmpeg and spleeter for audio processing and quality adjustments.
Since external command execution isn&amp;rsquo;t trackable through PHP&amp;rsquo;s memory monitoring, we used atop for detailed logging.
Service Setup ## Installation apt update &amp;amp;&amp;amp; apt install -y atop ## Modify the configuration file cat /etc/default/atop LOGOPTS=&amp;#34;&amp;#34; LOGINTERVAL=1 # Set to 1s for granular monitoring LOGGENERATIONS=28 # Retain logs for 28 days LOGPATH=/var/log/atop ## Start service systemctl start atop Diagnosis Process Alibaba Cloud monitoring showed a memory spike at 16:20:30: img.</description></item><item><title>Upgrading from Laravel5 to Laravel10: A Journey with Octane Containerization and Horizon Integration</title><link>https://sethix.com/posts/2024042811/</link><pubDate>Sun, 28 Apr 2024 11:02:51 +0800</pubDate><guid>https://sethix.com/posts/2024042811/</guid><description>While working on upgrading PHP versions, I took the opportunity to upgrade https://github.com/seth-shi/monday-shop from Laravel5 to Laravel10. Existing Solutions Paid option: https://laravelshift.com/ Open-source helper: https://laravel-upgrade-helper.github.io/ Upgrade Process Project Preparation Assume project path: /var/www/monday-shop Create a new Laravel10 project within the same directory: composer create-project laravel/laravel=10.* laravel10 New project path: /var/www/monday-shop/laravel10 Dependency Management Update dependencies: Merge require and require-dev sections from /var/www/monday-shop/laravel10/composer.json Delete old /var/www/monday-shop/composer.lock Resolve dependency conflicts: # Example conflict resolution composer install # Handle version conflicts iteratively Verify unused dependencies with composer depends xxx/xxxx File Migration Copy core files from new Laravel10 project: # Maintain directory structure while preserving custom modifications ├─app ├─bootstrap ├─config ├─database ├─public ├─resources ├─routes ├─storage ├─tests Process files folder-by-folder, comparing with custom implementations Error Resolution Start development server: php artisan serve Monitor storage/logs for errors Install missing helpers: composer require laravel/helpers Containerization with Octane Replace legacy laravel-s with official Octane: composer require laravel/octane Implement containerization using laravel-octane-dockerfile Key Configuration Files .</description></item><item><title>Using laravel-s in Docker (Including Queue Usage)</title><link>https://sethix.com/posts/2022030118/</link><pubDate>Tue, 01 Mar 2022 18:12:32 +0800</pubDate><guid>https://sethix.com/posts/2022030118/</guid><description>Environment Configuration FROM phpswoole/swoole:php7.4-alpine # A script for installing PHP extensions COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ RUN install-php-extensions pcntl redis pdo_mysql WORKDIR /var/www COPY . . RUN chmod -R 0777 storage &amp;amp;&amp;amp; \ chmod -R 0777 bootstrap/cache &amp;amp;&amp;amp; \ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ &amp;amp;&amp;amp; \ composer install --optimize-autoloader --no-dev &amp;amp;&amp;amp; \ php artisan config:cache &amp;amp;&amp;amp; \ php artisan route:cache &amp;amp;&amp;amp; \ php artisan view:cache &amp;amp;&amp;amp; \ php artisan laravels publish --no-interaction CMD [&amp;#34;php&amp;#34;, &amp;#34;bin/laravels&amp;#34;, &amp;#34;start&amp;#34;, &amp;#34;--env=product&amp;#34;] Deployment ## Build the image docker build .</description></item><item><title>Advanced Usage of Pyroscope for Go and PHP Performance Analysis</title><link>https://sethix.com/posts/2022021516/</link><pubDate>Tue, 15 Feb 2022 16:23:40 +0800</pubDate><guid>https://sethix.com/posts/2022021516/</guid><description>Installation Many online tutorials simply use a single Docker command:
docker run -it -p 4040:4040 --restart=always pyroscope/pyroscope:latest server However, this basic installation lacks crucial configurations: no authentication for the data dashboard, no API reporting restrictions (e.g., limiting reporting via API keys), and no data persistence after container destruction. Here&amp;rsquo;s a better approach using docker-compose.yml: version: &amp;#34;3&amp;#34; services: pyroscope: image: &amp;#34;pyroscope/pyroscope:latest&amp;#34; ports: - &amp;#34;4040:4040&amp;#34; command: - &amp;#34;server&amp;#34; environment: ## Enforce API key authentication for data ingestion - PYROSCOPE_AUTH_INGESTION_ENABLED=true ## Enable login for web dashboard - PYROSCOPE_AUTH_INTERNAL_ENABLED=true volumes: ## Persistent data storage - .</description></item><item><title>Troubleshooting Laravel-S Memory Leak with Swoole Tracker</title><link>https://sethix.com/posts/2022010510/</link><pubDate>Wed, 05 Jan 2022 10:54:45 +0800</pubDate><guid>https://sethix.com/posts/2022010510/</guid><description>Environment Setup Built using swoole:alpine Docker image FROM phpswoole/swoole:php7.4-alpine RUN sed -i &amp;#39;s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g&amp;#39; /etc/apk/repositories &amp;amp;&amp;amp; cat /etc/apk/repositories # Quick PHP extension installation COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ RUN install-php-extensions pcntl redis pdo_mysql WORKDIR /var/www COPY . . RUN chmod -R 0777 storage &amp;amp;&amp;amp; \ chmod -R 0777 bootstrap/cache &amp;amp;&amp;amp; \ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ &amp;amp;&amp;amp; \ composer install --optimize-autoloader --no-dev &amp;amp;&amp;amp; \ php artisan config:cache &amp;amp;&amp;amp; \ php artisan route:cache &amp;amp;&amp;amp; \ php artisan view:cache &amp;amp;&amp;amp; \ php artisan laravels publish --no-interaction CMD [&amp;#34;php&amp;#34;, &amp;#34;bin/laravels&amp;#34;, &amp;#34;start&amp;#34;, &amp;#34;--env=product&amp;#34;] For initial setup, comment out the last two lines in Dockerfile: docker build .</description></item><item><title>Containerizing All Services: Running PHP Code in Containers with Laravel-S</title><link>https://sethix.com/posts/2021102416/</link><pubDate>Sun, 24 Oct 2021 16:05:45 +0800</pubDate><guid>https://sethix.com/posts/2021102416/</guid><description>Preface Recently containerized all Go programs on the server for deployment Combined with CODING&amp;rsquo;s CI/CD, deployment has become extremely pleasant But there were still several PHP projects remaining on the server Blog (Originally built with WordPress) Deploy Nginx and PHP containers, then reverse proxy via host machine Discovered Hugo (similar to Hexo), a static site generator Migrated blog to Hugo with fast builds and real-time previews Now runs in a single Nginx container with host reverse proxy Details: My Blog DreamNote Admin (Laravel) Original Nginx + PHP-FPM container approach Switched to persistent PHP runtime using laravel-s (supports dcat-admin) Official Swoole container docker-swoole with custom Dockerfile: FROM phpswoole/swoole:php7.</description></item><item><title>A Slow API Incident Leading to Database Query Testing and Fully Automated API Test Assertions</title><link>https://sethix.com/posts/2021072215/</link><pubDate>Thu, 22 Jul 2021 15:08:54 +0800</pubDate><guid>https://sethix.com/posts/2021072215/</guid><description>Today during client-side testing, feedback indicated a slow API response. With the responsible colleague on leave, I investigated the project and confirmed the issue.
Added SQL logging in the controller: # SQL logging DB::listen(fn(QueryExecuted $query) =&amp;gt; Log::info($query-&amp;gt;sql)); # Log output [2021-07-22 12:46:15] local.INFO: select * from `albums` where `albums`.`id` = ? and `albums`.`deleted_at` is null limit 1 ... (repeated 24 times) The logs revealed multiple identical queries - a classic N+1 problem caused by missing eager loading Database query pseudocode: class Controller { public function index() { $models = Model::query()-&amp;gt;limit(20)-&amp;gt;get(); return ModelsResource::collection($models); } } class ModelsResource extends JsonResource { public function toArray($request) { return [ &amp;#39;id&amp;#39; =&amp;gt; $this-&amp;gt;id, &amp;#39;name&amp;#39; =&amp;gt; $this-&amp;gt;title, &amp;#39;album_id&amp;#39; =&amp;gt; $this-&amp;gt;album_id, // Problematic line &amp;#39;album_name&amp;#39; =&amp;gt; $this-&amp;gt;album-&amp;gt;title, ]; } } The resource accessed the album relationship without eager loading Solution: Add eager loading $models = Model::query()-&amp;gt;with(&amp;#39;album&amp;#39;)-&amp;gt;limit(20)-&amp;gt;get(); Prevention Strategies Problem detection is costly - better to prevent through automation Implemented HTTP testing with SQL query monitoring in base TestCase: public function json($method, $uri, array $data = [], array $headers = []) { $maxCount = 10; DB::enableQueryLog(); $response = parent::json($method, $uri, $data, $headers); $queries = collect(DB::getQueryLog())-&amp;gt;pluck(&amp;#39;query&amp;#39;); $this-&amp;gt;assertLessThan( $maxCount, $queries-&amp;gt;count(), sprintf(&amp;#34;Endpoint:%s[%s], SQL:%d\r\n%s&amp;#34;, $uri, $method, $maxCount, $queries-&amp;gt;implode(&amp;#34;\r\n&amp;#34;)) ); DB::flushQueryLog(); return $response; } Enhanced validation using unique query comparison: $duplicateQueries = $queries-&amp;gt;count() - $queries-&amp;gt;unique()-&amp;gt;count(); $this-&amp;gt;assertLessThan($maxDuplicates, $duplicateQueries, &amp;#34;Excessive duplicate queries&amp;#34;); Route coverage validation via custom test suite: &amp;lt;testsuite name=&amp;#34;End&amp;#34;&amp;gt; &amp;lt;file&amp;gt;tests/EndApiTest.</description></item><item><title>Solving Custom Page Refresh Issue with Admin PJAX by Breaking Out of Conventional Thinking</title><link>https://sethix.com/posts/2021070713/</link><pubDate>Wed, 07 Jul 2021 13:04:58 +0800</pubDate><guid>https://sethix.com/posts/2021070713/</guid><description>Using laravel-admin for backend development, we added a notification bell in the top-right corner Laravel Admin Notification Interface As shown above, clicking the bell icon should clear notifications and refresh the current page. Implemented using laravel-admin&amp;rsquo;s action: &amp;lt;?php namespace App\Admin\Actions\Custom; use Encore\Admin\Actions\Action; use Illuminate\Http\Request; class MarkNotificationRead extends Action { protected $selector = &amp;#39;.mark-notification-read&amp;#39;; public function handle(Request $request) { // forget notifications return $this-&amp;gt;response()-&amp;gt;success(&amp;#34;Marked all as read&amp;#34;)-&amp;gt;refresh(); } public function html() { // get notifications $count = 1; $countText = &amp;#34;&amp;lt;span class=\&amp;#34;label label-danger\&amp;#34;&amp;gt;{$count}&amp;lt;/span&amp;gt;&amp;#34;; return &amp;#34;&amp;lt;li title=&amp;#39;Click to mark as read&amp;#39;&amp;gt; &amp;lt;a href=\&amp;#34;#\&amp;#34; class=&amp;#39;mark-notification-read&amp;#39;&amp;gt; &amp;lt;i data-count=&amp;#39;{$count}&amp;#39; id=&amp;#39;notification&amp;#39; class=\&amp;#34;fa fa-bell fa-rotate-0\&amp;#34;&amp;gt;&amp;lt;/i&amp;gt; {$countText} &amp;lt;/a&amp;gt; &amp;lt;/li&amp;gt;&amp;#34;; } } The pseudo-code above implements the notification feature.</description></item><item><title>A Bug Caused by Static Variables in Laravel Queues</title><link>https://sethix.com/posts/2021070612/</link><pubDate>Tue, 06 Jul 2021 12:43:13 +0800</pubDate><guid>https://sethix.com/posts/2021070612/</guid><description>Environment PHP_VERSION=7.4 laravel/framework: ^7.0 Static Variables In many programming languages, static variables are defined as variables that: Have the same lifecycle as the program Are initialized only once However, in PHP&amp;rsquo;s common runtime environment (php-fpm mode), processes get recycled after each request, so static variables don&amp;rsquo;t persist in memory (only effective during the current request) Official PHP documentation states: &amp;ldquo;Another important feature of variable scoping is the static variable. A static variable exists only in a local function scope, but it does not lose its value when program execution leaves this scope.</description></item><item><title>A Lesson Learned from Laradock Cron Job Failures</title><link>https://sethix.com/posts/2021070211/</link><pubDate>Fri, 02 Jul 2021 11:25:44 +0800</pubDate><guid>https://sethix.com/posts/2021070211/</guid><description>Debugging Steps The cron jobs in laradock are executed in the workspace container. Check logs using: docker-compose logs -f workspace Sample log output:
Jul 2 12:26:59 9b6ec4d18dd1 syslog-ng[12]: syslog-ng starting up; version=&amp;#39;3.13.2&amp;#39; workspace_1 | *** Booting runit daemon... workspace_1 | *** Runit started as PID 20 workspace_1 | Jul 2 12:27:00 9b6ec4d18dd1 cron[23]: (CRON) INFO (pidfile fd = 3) ... Enter the container: docker-compose exec workspace bash Test cron job execution without suppressing output: /usr/bin/php /var/www/artisan schedule:run Permission Issues Logs in /storage/logs showed permission errors when created by root user.</description></item><item><title>How to Remove the Core Service - Views in Laravel</title><link>https://sethix.com/posts/2021052616/</link><pubDate>Wed, 26 May 2021 16:54:46 +0800</pubDate><guid>https://sethix.com/posts/2021052616/</guid><description>Previous article: Speed Up Your Service Performance by Reducing Service Provider Boot Time 2.0 A reader mentioned errors when directly removing the View service. This article demonstrates how to properly remove the View service. Step-by-Step Guide 1. Create a New Laravel Project composer create-project laravel/laravel=7.* laravel-demo 2. Modify the Default Route Edit routes/web.php to return JSON instead of a view:
Route::get(&amp;#39;/&amp;#39;, function () { return [ &amp;#39;code&amp;#39; =&amp;gt; 200, &amp;#39;msg&amp;#39; =&amp;gt; &amp;#39;hello&amp;#39; ]; }); 3.</description></item><item><title>Optimizing Laravel Performance by Reducing Service Providers Boot 2.0</title><link>https://sethix.com/posts/2021052512/</link><pubDate>Tue, 25 May 2021 12:08:42 +0800</pubDate><guid>https://sethix.com/posts/2021052512/</guid><description>Performance has always been one of the most discussed topics in Laravel, yet it has brought fresh perspectives to many PHP developers. Let&amp;rsquo;s optimize this framework once again.
Fundamentals (Common Knowledge) Use Redis drivers for caching, sessions, and queues Framework built-in caching: Route caching: php artisan route:cache Configuration caching: php artisan config:cache Implement caching based on API idempotency Upgrades OPcache: Enable it without hesitation Set opcache.validate_timestamps=0 to prevent automatic code updates in production (similar to compiled languages).</description></item><item><title>A Bug Caused by Combined Array Index Changes and Reference Parameters in PHP</title><link>https://sethix.com/posts/2021031412/</link><pubDate>Sun, 14 Mar 2021 12:07:42 +0800</pubDate><guid>https://sethix.com/posts/2021031412/</guid><description>Today, our team encountered a bug reported in the group chat. After cloning the project locally, I spent some time reproducing the issue.
Code Overview The following code causes the first item removal to convert a Collection into an object (JSON data): protected function transformJson($items) { return Collection::make($items) - -&amp;gt;values() -&amp;gt;where(&amp;#39;_remove_&amp;#39;, &amp;#39;0&amp;#39;) + -&amp;gt;values() -&amp;gt;map(fn($item) =&amp;gt; Arr::except($item, &amp;#39;_remove_&amp;#39;)) -&amp;gt;toJson(); In the API data retrieval logic, this function call pattern caused issues: public function index() { // $json={&amp;#34;1&amp;#34;:{&amp;#34;id&amp;#34;: 2}} $data = Collection::make($json); // Filtering converts indexes to 0-based $index = $this-&amp;gt;getRandomAd($data, [1]); // Returns null due to original key mismatch return $data-&amp;gt;get($index); } protected function getRandomAd(Collection $data, $notIn=[]) { $index = -1; if (count($notIn) &amp;gt; 0) { $data = $data-&amp;gt;filter(fn($item) =&amp;gt; !</description></item><item><title>Slim - PHP - Laravel Performance Test</title><link>https://sethix.com/posts/2019112515/</link><pubDate>Mon, 25 Nov 2019 15:32:13 +0800</pubDate><guid>https://sethix.com/posts/2019112515/</guid><description>Test Environment Local Configuration (Win 10 i7-8565U 16G)(Nginx 1.15.11)(MySQL 5.5.62) Cloud Server (1 Core 2G)(Nginx 1.16.1)(MySQL 5.5.62) Performance Results Software Database Model Local QPS Cloud Server QPS Laravel 6.3.0 (with session) ORM 12.11 5.15 Laravel 6.3.0 (with session) PDO 13.85 5.31 Laravel 6.3.0 ORM 13.06 5.69 Laravel 6.3.0 PDO 13.98 5.89 Slim 4.3.0 PDO 41.04 43.65 PHP 7.1.9 Native PDO 52.85 51.81 Notes All tests performed using ApacheBench (ab) with command:</description></item><item><title>Implementation of Coupon Functionality</title><link>https://sethix.com/posts/2019090423/</link><pubDate>Wed, 04 Sep 2019 23:06:17 +0800</pubDate><guid>https://sethix.com/posts/2019090423/</guid><description>Recently I&amp;rsquo;ve developed several e-commerce projects, which inevitably involved designing coupon systems.
Since the Monday Mall project didn&amp;rsquo;t have this module, I decided to implement it during this period.
Referencing JD.com&amp;rsquo;s style, created a template like this:
Coupon Here&amp;rsquo;s the core logic:
First, we need a coupon template table Stores coupon templates for backend generation and user redemption Requires a separate user coupon table Table structure overview:
Coupon # Template Table `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT &amp;#39;Coupon title&amp;#39;, `amount` decimal(8,2) NOT NULL COMMENT &amp;#39;Discount amount&amp;#39;, `full_amount` decimal(8,2) NOT NULL COMMENT &amp;#39;Minimum purchase amount&amp;#39;, `score` int(10) unsigned NOT NULL DEFAULT &amp;#39;0&amp;#39; COMMENT &amp;#39;Redemption points required&amp;#39;, `start_date` date NOT NULL COMMENT &amp;#39;Start date&amp;#39;, `end_date` date NOT NULL COMMENT &amp;#39;Expiry date&amp;#39;, `created_at` timestamp NULL DEFAULT NULL COMMENT &amp;#39;Creation time&amp;#39;, `updated_at` timestamp NULL DEFAULT NULL COMMENT &amp;#39;Update time&amp;#39;, # User Coupon Table `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned COMMENT &amp;#39;User ID&amp;#39;, `title` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT &amp;#39;Coupon title&amp;#39;, `amount` decimal(8,2) NOT NULL COMMENT &amp;#39;Discount amount&amp;#39;, `full_amount` decimal(8,2) NOT NULL COMMENT &amp;#39;Minimum purchase amount&amp;#39;, `start_date` date NOT NULL COMMENT &amp;#39;Start date&amp;#39;, `end_date` date NOT NULL COMMENT &amp;#39;Expiry date&amp;#39;, `used_at` timestamp NULL DEFAULT NULL COMMENT &amp;#39;Usage time&amp;#39;, `created_at` timestamp NULL DEFAULT NULL COMMENT &amp;#39;Creation time&amp;#39;, `updated_at` timestamp NULL DEFAULT NULL COMMENT &amp;#39;Update time&amp;#39;, Key workflow:</description></item><item><title>[monday-shop] Issues and Solutions Encountered During Dependency Updates</title><link>https://sethix.com/posts/2019082411/</link><pubDate>Sat, 24 Aug 2019 11:17:03 +0800</pubDate><guid>https://sethix.com/posts/2019082411/</guid><description>This weekend, I updated the monday-shop system.
The most significant challenges came from upgrading laravel-admin to the latest version. This backend framework is particularly valuable as it allows developers to focus on core backend logic. First Issue: Composer Dependency Errors
Initial composer install failed due to locked mirror sources. Solved by switching to Alibaba Cloud Composer Mirror.
Laravel-admin Upgrade Challenges
monday-shop Key functionality affected:
Soft Delete (下架) Restore (上架) Version-Specific Problems:</description></item><item><title>Speed Up Your Framework: How to Reduce Service Provider Boot Time</title><link>https://sethix.com/posts/2019032219/</link><pubDate>Fri, 22 Mar 2019 19:32:57 +0800</pubDate><guid>https://sethix.com/posts/2019032219/</guid><description>Laravel has a powerful feature called service providers that makes it easy to access various services. However, this convenience comes at the cost of framework bloat. Here&amp;rsquo;s how to optimize unnecessary service providers.
Step 1: Identify Unnecessary Service Providers Run php artisan package:discover or composer dump-auto to see all auto-loaded service providers:
Service Providers Step 2: Conditionally Load Providers Example 1: Admin Panel Optimization The encore/laravel-admin package (a backend panel) boots on every request.</description></item><item><title>In Route Permission Control, a Paginated List Permission Can Simultaneously Control All List Permissions</title><link>https://sethix.com/posts/2018101716/</link><pubDate>Wed, 17 Oct 2018 16:12:05 +0800</pubDate><guid>https://sethix.com/posts/2018101716/</guid><description>Recently encountered an issue while implementing permission control for API endpoints.
This builds upon our previous permission control method: Using Route-Based Permission Control in Laravel (Applicable Beyond Laravel, as a Conceptual Approach)
We have two route aliases:
Paginated city list: cities.index
Complete city list: cities.index.all
These represent two separate permissions. To ensure users with only the cities.index permission can also access cities.index.all (since both belong to list operations under normal logic), we need to make minor adjustments to our validation logic.</description></item><item><title>Elegantly Validate Date Must Be Greater Than Today in Laravel</title><link>https://sethix.com/posts/2018091911/</link><pubDate>Wed, 19 Sep 2018 11:51:03 +0800</pubDate><guid>https://sethix.com/posts/2018091911/</guid><description>We often encounter scenarios like ticket purchasing queries that require date range validation: the start date must be greater than or equal to today, and the end date must be greater than or equal to the start date. Version Laravel 5.5.40 PHP 7.1 Implementation Steps Create a Form Request:
Laravel Note: Remember to return true in the authorize() method since we&amp;rsquo;re handling authentication elsewhere
Basic validation rules:
Laravel Special validation challenge:</description></item><item><title>A Pitfall When Developing Optional Token-Passing API Interfaces</title><link>https://sethix.com/posts/2018062412/</link><pubDate>Sun, 24 Jun 2018 12:04:42 +0800</pubDate><guid>https://sethix.com/posts/2018062412/</guid><description>When developing APIs, authentication is inevitable. I use jwt-auth for this purpose. A common issue in authentication is token expiration. In the default settings of config/jwt.php, the expiration time is one hour. For better security, I&amp;rsquo;ve set it to 5 minutes. Forcing users to re-login every 5 minutes would lead to terrible user experience. This is where token refresh functionality becomes essential. Normally, we create a dedicated token refresh endpoint.</description></item><item><title>Laravel Form size Validation for Numbers</title><link>https://sethix.com/posts/2018060110/</link><pubDate>Fri, 01 Jun 2018 10:15:17 +0800</pubDate><guid>https://sethix.com/posts/2018060110/</guid><description>To validate a numeric exact value, I referred to the form validation documentation:
size:value
The field under validation must have a size matching the given value. For string data, value corresponds to the number of characters. For numeric data, value corresponds to the integer value. For arrays, size corresponds to the count of the array. For files, size corresponds to the file size in kilobytes.
Original validation rule:
$data = [&amp;#39;age&amp;#39; =&amp;gt; 9]; $validator = \Illuminate\Support\Facades\Validator::make($data, [&amp;#39;age&amp;#39; =&amp;gt; &amp;#39;required|size:9&amp;#39;]); if ($validator-&amp;gt;fails()) { dd($validator-&amp;gt;errors()-&amp;gt;first()); } dd(&amp;#39;pass&amp;#39;); I expected it to validate numbers directly when the input 9 is an integer.</description></item><item><title>How I Contributed to Laravel's Source Code for the First Time</title><link>https://sethix.com/posts/2018051416/</link><pubDate>Mon, 14 May 2018 16:17:35 +0800</pubDate><guid>https://sethix.com/posts/2018051416/</guid><description>Origin Solutions always outnumber problems, making problem discovery more valuable than problem-solving itself. The story began when debugging model events - I randomly inserted a string ID (non-standard UUID) into the database and found the model couldn&amp;rsquo;t be retrieved by this ID in my model events. When encountering issues, it&amp;rsquo;s worth checking Laravel&amp;rsquo;s issue tracker to find solvable problems. Progress After verifying my code wasn&amp;rsquo;t faulty through step-by-step debugging
Controller Event Log Discovered the ID returned by belongsToMany::sync method was incorrect</description></item><item><title>Permission Control via Routing in Laravel (Not Limited to Laravel, Just a Conceptual Approach)</title><link>https://sethix.com/posts/2018032712/</link><pubDate>Tue, 27 Mar 2018 12:53:51 +0800</pubDate><guid>https://sethix.com/posts/2018032712/</guid><description>Start Permission design is a crucial feature for backend management systems. PHP already has many mature packages for this purpose, so we don&amp;rsquo;t need to reinvent the wheel (though you certainly can if preferred).
PS Here are two common historical approaches for permission verification:
Verify required permissions individually on each page Centralized verification via middleware First, let&amp;rsquo;s examine a simplified database schema (retaining only critical fields) with its ER diagram: Database Model Diagram (Note: In this design, users don&amp;rsquo;t directly possess permissions but inherit them through roles.</description></item><item><title>Insights on Developing RESTful APIs with Laravel</title><link>https://sethix.com/posts/2018030122/</link><pubDate>Thu, 01 Mar 2018 22:06:16 +0800</pubDate><guid>https://sethix.com/posts/2018030122/</guid><description>Here are some insights I’ve gained while working with Laravel to develop RESTful APIs.
Getting Started API Authentication: For public APIs, consider OAuth2.0; for private/internal APIs, token-based authentication (e.g., JWT) is often sufficient. Versioning: Include an API version in routes for future scalability: Route::prefix(&amp;#39;v1&amp;#39;)-&amp;gt;group(function () { // Routes here }); CORS Handling: Use the barryvdh/laravel-cors package for seamless cross-origin requests. Sample API Endpoint
Example Code Authentication Use jwt-auth for JWT-based authentication.</description></item></channel></rss>