Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Resource Laravel Package

sylius/resource

Sylius Resource is a lightweight foundation for building domain resources in Symfony apps. It provides resource configuration, controllers, repositories, events, and form/grid integration to speed up CRUD and admin tooling while keeping your domain and persistence clean.

View on GitHub
Deep Wiki
Context7

[READ-ONLY] Resource management abstraction for PHP.

Frequently asked questions about Resource
Can sylius/resource work with Laravel’s Eloquent ORM, or is it only for Doctrine?
sylius/resource is ORM-agnostic but requires a custom `ResourceRepository` for Eloquent. You’ll need to extend `EloquentResourceRepository` and implement your repository interface. Doctrine users get built-in support with `DoctrineResourceRepository`, reducing setup time.
How does sylius/resource integrate with Laravel’s built-in validation (e.g., FormRequest)?
The package doesn’t replace Laravel’s validation but works alongside it. You can use Laravel’s `FormRequest` classes to validate incoming data, then map the validated data to your resource entities. The resource layer handles persistence, while validation remains decoupled.
What’s the performance impact of using sylius/resource compared to raw Eloquent queries?
The overhead is minimal for most CRUD operations. The abstraction adds a thin layer between your domain logic and the repository, but queries remain optimized. For complex queries, you can still use Eloquent’s query builder directly within custom repository methods.
How do I migrate an existing Eloquent model to use sylius/resource without breaking changes?
Start by creating a `ResourceInterface` for your model, then implement a custom `ResourceRepository` (e.g., `EloquentResourceRepository`). Gradually replace direct `Model` usage in controllers/services with resource methods. Use IDE refactoring tools to simplify the transition.
Does sylius/resource support soft deletes or other advanced Eloquent features?
Soft deletes require custom implementation in your `ResourceRepository`. Extend `EloquentResourceRepository` and override methods like `delete()` to use Eloquent’s `forceDelete()` or soft-delete logic. The package doesn’t enforce soft deletes by default to keep it flexible.
Can I use sylius/resource with Laravel’s API Resources for JSON serialization?
sylius/resource handles serialization differently but can coexist with Laravel’s `ApiResource`. You can manually transform resources to JSON in controllers or use a hybrid approach where resources are serialized via their own methods while leveraging `ApiResource` for API-specific logic.
What’s the learning curve for a Laravel team new to DDD or Sylius’s resource pattern?
Teams unfamiliar with DDD may take 2–4 weeks to adapt, depending on complexity. Focus on understanding `ResourceInterface`, repositories, and events. Start with simple resources (e.g., `User`, `Product`) to build intuition before tackling complex aggregates.
How do I handle domain events (e.g., ResourceCreated) in Laravel’s event system?
sylius/resource fires domain events (e.g., `ResourceCreated`, `ResourceUpdated`) that you can dispatch to Laravel’s event system. Listen for these events in your `EventServiceProvider` and trigger side effects like notifications or logging. Example: `event(new ResourceCreated($resource));`
Are there alternatives to sylius/resource for DDD in Laravel, and how do they compare?
Alternatives include `spatie/laravel-model-based-api-resources` (simpler, API-focused) or `asgardcms/common` (monolithic, less flexible). sylius/resource stands out for its DDD alignment, event-driven design, and ORM flexibility, making it ideal for complex domain logic.
How do I test controllers or services that use sylius/resource with PHPUnit?
Mock the `ResourceRepositoryInterface` in your tests to isolate domain logic. Use PHPUnit’s mock builder to create fake repositories, then inject them into your services/controllers. For integration tests, use in-memory databases or seed test data via repositories.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views