Controller
class Controller extends Controller
The main Controler to inherit from.
Properties
protected array | $key_mapping | Maps request parameters to database columns. | |
protected array | $relations | The relations to load with the model from the DB. | |
protected Formatter | $formatter_class | Use this to simply override the Formatter. | |
protected ModelMapping | $model_mapping_class | Use this to simply override the ModelMapping. | |
protected RequestAdapter | $request_adapter_class | Use this to simply override the RequestAdapter. | |
$request_adapter | |||
$request | |||
protected | $model | ||
protected | $model_mapping | ||
protected | $formatter | ||
protected | $input | ||
protected | $resource | ||
protected | $collection |
Methods
No description
Request Handler: List all resources.
Request Handler: Create a new resource.
Request Handler: Show a single resource.
Request Handler: Update a resource.
Request Handler: Delete a resource.
Fetch a single record from the DB and store it to $this->resource.
Fetch a Collection of Resources from the databse and store it to $this->collection.
Generate the response data using our Formatter.
Generate the response data using our Formatter.
Apply filters based on the $key_mapping. If a key is present in the request, an appropriate where clause will be added to the query.
Get the request data from the adapter and store it to $this->input.
Validate the input data using the appropriate validator.
Create a new instance of the current Model, fill it with the input data, save it to the database and load it anew to get all attributes populated.
Update the resource with the input data.
Delete the resource.
No description
Load a fresh instance of the current resource from the database.
Return a ModelMapping instance.
Return a Formatter instance.
Return a RequestAdapter instance.
Make sure the authenticated user is allowed to perform this type of $action.
Make sure the authenticated user is allowed to perform this type of $action on $this->resource.
A hook to customize the query for all single resource queries.
A hook to customize the query for all collection queries.
This is the place to manipulate the validation rules at runtime.
Hook in here to customize the input before saving a resource.
Hook in here to customize actions after saving a resource
Hook in here to customize the input before creating a resource.
Hook in here to customize the input before updating a resource.
Use this hook to apply custom logic after the controller instance has been created.
Details
at line line 102
__construct(
Request $request)
at line line 123
Response
index()
Request Handler: List all resources.
at line line 136
Response
store()
Request Handler: Create a new resource.
at line line 151
Response
show()
Request Handler: Show a single resource.
at line line 165
Response
update()
Request Handler: Update a resource.
at line line 182
Response
destroy()
Request Handler: Delete a resource.
at line line 204
protected
void
getResource()
Fetch a single record from the DB and store it to $this->resource.
at line line 222
protected
void
getCollection()
Fetch a Collection of Resources from the databse and store it to $this->collection.
at line line 235
protected
void
formatResource()
Generate the response data using our Formatter.
at line line 245
protected
void
formatCollection()
Generate the response data using our Formatter.
at line line 258
protected
Builder
filterByRequest(
Builder $query,
Array $mapping = null)
Apply filters based on the $key_mapping. If a key is present in the request, an appropriate where clause will be added to the query.
at line line 291
protected
void
gatherInput()
Get the request data from the adapter and store it to $this->input.
at line line 302
protected
void
validateInput(
bool $only_present = false)
Validate the input data using the appropriate validator.
at line line 316
protected
void
createResource()
Create a new instance of the current Model, fill it with the input data, save it to the database and load it anew to get all attributes populated.
at line line 341
protected
void
updateResource()
Update the resource with the input data.
at line line 356
protected
void
destroyResource()
Delete the resource.
at line line 361
protected
makeResponse($response_data = null, $status_code = 200)
at line line 375
protected
void
refreshResource()
Load a fresh instance of the current resource from the database.
at line line 395
protected
ModelMapping
makeModelMapping()
Return a ModelMapping instance.
This can be used to dynamically customize the mapping, for example based on Auth/Roles.
at line line 408
protected
Formatter
makeFormatter(
ModelMapping $mapping)
Return a Formatter instance.
This can be used to dynamically customize the formatter.
at line line 421
protected
RequestAdapter
makeRequestAdapter(
Request $request)
Return a RequestAdapter instance.
This can be used to dynamically customize the adapter.
at line line 433
protected
void
authorizeAction(
String $action)
Make sure the authenticated user is allowed to perform this type of $action.
at line line 442
protected
void
authorizeResource(
String $action)
Make sure the authenticated user is allowed to perform this type of $action on $this->resource.
at line line 450
protected
Builder
adaptResourceQuery(
Builder $query)
A hook to customize the query for all single resource queries.
at line line 461
protected
Builder
adaptCollectionQuery(
Builder $query)
A hook to customize the query for all collection queries.
at line line 472
protected
Array
adaptRules(
array $rules)
This is the place to manipulate the validation rules at runtime.
at line line 484
protected
void
beforeSave()
Hook in here to customize the input before saving a resource.
This happens in both the create and update actions.
at line line 493
protected
void
afterSave()
Hook in here to customize actions after saving a resource
This happens in both the create and update actions.
at line line 500
protected
void
beforeCreate()
Hook in here to customize the input before creating a resource.
at line line 507
protected
void
beforeUpdate()
Hook in here to customize the input before updating a resource.
at line line 515
protected
void
afterConstruct()
Use this hook to apply custom logic after the controller instance has been created.