Defining Resources

All resources and their configurations are defined within bakery.models, you can see an example configuration file here

Defining a Resource

In the following example users will be registered as a resource, with browse and read functionality available to authenticated users who can pass the admin gate

The definition of the model within the users key denotes that users is the resource slug to be utilised.

'models' => [
    'users' => [
        'model' => \App\User::class,
        'security' => [
            'gate' => 'admin'
        ],
        'enabled' => ['browse', 'read']
    ]
]

Enabled Methods

The following are the methods which can be added to the array to enable functionality. Naturally this also takes into account the relevant security configurations.

  • browse allows for searching and filtering of the resources, according to your configuration

  • read allows for the reading of a single resource

  • post allows the creation of a resource

  • put allows the holistic update of a resource

  • patch allows the partial update of a resource

  • delete allows the deletion of a resource

Transformation

There are 3 different resource-wide transformations available, which can be inherited by the specified methods for the resource, these are defined below

  • resource is the default HTTP Resource to be used when returning a model. If not specified, or null, then the model will be returned

  • collection is the default HTTP Resource to be used when returning a collection of models. If not specified, or null, then the Eloquent Collection will be returned

  • modifier is a class, implementing the ModifiesBakeryResource interface, which is used to modify a resource immediately before save

Events

Events are dispatched throughout the Bakery, a global bakery.models.{resource}.events can be used to dispatch a series of events any time a model receives a successful POST PUT or PATCH request.

The events defined here will be dispatched in addition to any defined events on the models and methods themselves.

Last updated

Was this helpful?