Laravel Eloquent: has vs with vs whereHas?

with with() is for eager loading, it means the relationship data is loaded at the time you query the parent model, where eager loading will alleviate the “N+1” query problem. Example:User -> hasMany -> Post has has() is to filter the selecting model based on a relationship. So it acts very similarly to a normalContinue reading “Laravel Eloquent: has vs with vs whereHas?”

Unit Testing Laravel: InvalidArgumentException, fail to locate factory classes (Unknown formatter)

Error: Unit-Test fail to locate factory class but running the same factory in tinker (no issue in tinker). For Laravel 6.8 or above, changes were made to “Unit-Test” to not loaded the framework anymore. So, if you need to use a “Factory” you should create a test within the “Feature-Test” directory or: use this (inContinue reading “Unit Testing Laravel: InvalidArgumentException, fail to locate factory classes (Unknown formatter)”

Composer: Content-Length mismatch, received 372 bytes out of the expected 291742

When trying to update the Laravel installer using Composer, a content length mismatch exception may occur. This error is because the composer repository key for the packagist has changed from “packagist” (prior to composer V1.2.3) to “packagist.org”: Solution to this error, just change the composer default repo url: composer config -g repo.packagist composer https://packagist.org composerContinue reading “Composer: Content-Length mismatch, received 372 bytes out of the expected 291742”