bfg/resource
BFG Resource is a Laravel package for defining reusable resource classes that keep controllers lean and API responses consistent. It helps organize resource logic, streamline CRUD workflows, and deliver structured data across your application, making resource handling easier to maintain as your app...
Install it the standard Composer way.
composer require bfg/resource
The package is small enough that auto-discovery (if a service provider ships) or a manual providers entry in config/app.php is the only wiring you'll need. Check composer.json in the repo for the extra.laravel.providers key before assuming you're done.
Read the source before the README. With 1 star and 0 dependents, documentation will lag the code. Start with:
src/ — see what actually ships (base class, traits, collection helpers).composer.json — confirm the PSR-4 namespace (likely Bfg\Resource\...) and minimum Laravel version.README.md — expect a skeleton; treat any examples as aspirational until you've run them.First real use case. Given the description ("a small addition to the resources"), the entry point is almost certainly a base resource class you extend instead of Illuminate\Http\Resources\Json\JsonResource. Create one resource against a model you already expose, e.g.:
use Bfg\Resource\...; // confirm the actual class name in src/
class UserResource extends /* package base */
{
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
];
}
}
Then return it from a controller and hit the route with Accept: application/json. If the payload shape is what you expect, the package is behaving as a thin wrapper; if not, you've found your first integration quirk.
Write a smoke test immediately. One feature test that hits the endpoint and asserts the JSON structure will save you hours, because the package's behavior is under-documented.
Resource class extending Laravel's JsonResource. Extend it and keep your toArray() logic in your own class — treat the package as a thin convention layer, not a framework.Route::get(...)->...), never from models or repositories. This keeps the package's behavior isolated to the HTTP edge, so you can rip it out later if needed.ResourceCollection), use it for list endpoints so pagination metadata (links, meta) is handled consistently. Verify the shape it emits against Laravel's default before your frontend depends on it.whenLoaded() / when() from Laravel — these are inherited if the base class extends JsonResource. The package addition, whatever it is, rarely replaces these.public function show(User $user)
{
return new UserResource($user);
}
Keep the response class as the only thing the controller knows about; don't sprinkle package-specific helpers across controllers.composer.json ("bfg/resource": "x.y.*") so an unexpected update doesn't silently change your API responses.Resource) overlap with App\Http\Resources\... or Illuminate\Http\Resources\..., imports get confusing fast. Alias explicitly:
use Bfg\Resource\Resource as BfgResource;
laravel/framework constraint that lags current versions. Check composer.json and run composer why-not bfg/resource if installation fails on your Laravel version.dd($resource->resolve(request())) reveals exactly what the package's toArray produced versus what Laravel wrapped around it.config/resource.php with defaults (wrapper key, pagination meta shape). If it exists, publish it (php artisan vendor:publish --tag=...) so you control the defaults rather than the package author.toArray() free of package-specific method calls where possible. If the package stalls, swapping back to JsonResource should be a search-and-replace of the base class, not a rewrite.How can I help you explore Laravel packages today?