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.
browseallows for searching and filtering of the resources, according to your configurationreadallows for the reading of a single resourcepostallows the creation of a resourceputallows the holistic update of a resourcepatchallows the partial update of a resourcedeleteallows 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
resourceis the default HTTP Resource to be used when returning a model. If not specified, ornull,then the model will be returnedcollectionis the default HTTP Resource to be used when returning a collection of models. If not specified, ornull, then the Eloquent Collection will be returnedmodifieris a class, implementing theModifiesBakeryResourceinterface, 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?