46 articles

📰 Dev.to · Recca Tsai

Articles from Dev.to · Recca Tsai · 46 articles · Updated every 3 hours · View all reads

All ⚡ AI Lessons (11037) ArXiv cs.AIDev.to · FORUM WEBDev.to AIForbes InnovationOpenAI NewsHugging Face Blog
2 Ways to Fake $_SERVER Variables in Laravel Feature Tests
Dev.to · Recca Tsai 1mo ago
2 Ways to Fake $_SERVER Variables in Laravel Feature Tests
Fake $_SERVER in Laravel feature tests by passing server vars per-request, or use withServerVariables() to apply them globally for the entire test method.
Laravel Testing: Assert Final Page Content After a Redirect
Dev.to · Recca Tsai 1mo ago
Laravel Testing: Assert Final Page Content After a Redirect
POST requests only return a 302, hiding the final page. Use followingRedirects() to automatically follow redirects and assert on the destination page content.
Add MySQL Functions to SQLite in Laravel Tests
Dev.to · Recca Tsai 1mo ago
Add MySQL Functions to SQLite in Laravel Tests
SQLite throws "no such function" for MySQL-specific functions like FIELD. Use PDO sqliteCreateFunction in TestCase setUp to register them and make tests pass.
Laravel Queue Job Reads Stale Data in Transaction: Fix
Dev.to · Recca Tsai 1mo ago
Laravel Queue Job Reads Stale Data in Transaction: Fix
Jobs dispatched in a transaction re-query the DB via SerializesModels before commit, reading stale data. Use afterCommit() to delay dispatch until after commit.
Laravel LazyCollection Loses Lazy Evaluation with Generator
Dev.to · Recca Tsai 1mo ago
Laravel LazyCollection Loses Lazy Evaluation with Generator
Passing a Generator directly to LazyCollection causes iterator_to_array to expand it all at once. Wrap it in a Closure to restore true lazy evaluation.
Fix Laravel Migration Unknown Database Type Enum Error
Dev.to · Recca Tsai 1mo ago
Fix Laravel Migration Unknown Database Type Enum Error
Doctrine DBAL does not recognize MySQL enum type, causing migration failures. Covers Type::addType and registerDoctrineTypeMapping with when to use each fix.
How Laravel Facade Resolves Instances from the Container
Dev.to · Recca Tsai 1mo ago
How Laravel Facade Resolves Instances from the Container
Laravel Facade uses getFacadeAccessor to resolve instances from the Container. This post shows the difference between bind and singleton and how custom Facades
Mock IteratorAggregate with Mockery to Fix foreach in Tests
Dev.to · Recca Tsai 1mo ago
Mock IteratorAggregate with Mockery to Fix foreach in Tests
Mocking IteratorAggregate breaks foreach in PHPUnit. Return an ArrayObject from the mocked getIterator method to make foreach iterate over test data correctly.
PHPUnit: Test Closures with Mockery::spy
Dev.to · Recca Tsai 1mo ago
PHPUnit: Test Closures with Mockery::spy
Assertions inside a closure pass silently even if never called. Wrap the closure in Mockery::spy to verify invocation count and arguments in PHPUnit tests.
Eloquent Macro: Fire Specific Events After saveQuietly
Dev.to · Recca Tsai 1mo ago
Eloquent Macro: Fire Specific Events After saveQuietly
Save a model silently with saveQuietly, then selectively dispatch created or other Eloquent model events via a custom Builder macro fire method in Laravel.
Fix PHP Curl Comodo SSL Expired Error with GuzzleHttp verify
Dev.to · Recca Tsai 1mo ago
Fix PHP Curl Comodo SSL Expired Error with GuzzleHttp verify
PHP Curl throws a Comodo RSA SSL expired error on Linux due to missing Root CA. Use GuzzleHttp verify to point to the certificate file, globally or per service.
Why Laravel min/max Fails on Numbers: Add the numeric Rule
Dev.to · Recca Tsai 1mo ago
Why Laravel min/max Fails on Numbers: Add the numeric Rule
Laravel min/max rules compare string length by default, letting 0 pass validation. Add the numeric rule to switch to value comparison and fix the bug.
3 Laravel Migration Pitfalls and How to Fix Them
Dev.to · Recca Tsai 1mo ago
3 Laravel Migration Pitfalls and How to Fix Them
Avoid 3 migration rollback mistakes: mixing add/drop in one closure, dropping index and column together, and multiple dropColumn calls. Catch them with SQLite.
Speed Up Laravel Tests 7x with PDO::exec Schema Load
Dev.to · Recca Tsai 1mo ago
Speed Up Laravel Tests 7x with PDO::exec Schema Load
Load schema dump into SQLite in-memory database via PDO::exec, skipping per-file migrations. Cuts Laravel test time from 2:21 minutes down to 18 seconds.
Laravel 10 Database Expression: Cross-Database SQL
Dev.to · Recca Tsai 1mo ago
Laravel 10 Database Expression: Cross-Database SQL
MySQL's IF() fails on SQLite. Laravel 10's Expression interface generates Grammar-specific SQL, encapsulating cross-database differences into a reusable class.
Use Laravel Container bind to Inject Any Third-Party Package
Dev.to · Recca Tsai 1mo ago
Use Laravel Container bind to Inject Any Third-Party Package
When a third-party class needs constructor parameters, Laravel cannot auto-resolve it. Register it with bind in a ServiceProvider to enable type-hint injection.
Render Markdown with Blade and Embed Dynamic Syntax
Dev.to · Recca Tsai 1mo ago
Render Markdown with Blade and Embed Dynamic Syntax
Use Blade addExtension to make .md files support @include and variables, then pass the output through CommonMark to generate HTML for dynamic documentation.
Alpine.js Plugin for Laravel AJAX Validation Errors
Dev.to · Recca Tsai 1mo ago
Alpine.js Plugin for Laravel AJAX Validation Errors
Build an Alpine.js errors plugin that mirrors the Laravel MessageBag API, so 422 AJAX validation errors display just as easily as the @error directive.