-
Notifications
You must be signed in to change notification settings - Fork 6
API Development
johnenrick edited this page Apr 28, 2017
·
1 revision
To create an API follow the steps below
- Create a migration for each table in database. The rull of thumb is one API for one database table.
- Create controller and model using php artisan. Note: controller name must have a Controller postfix
- Extend the created controller and model with APIController and APIModel
- Configure the controller. See API Controller Configuration
- Open routes/api_routes.php and add the new route
- Test the API by visiting
localhost:8000/api/controller_name/operations. operations can becreate,retrieve,update,delete
To add the API model for the controller, set $this->model = new Item(); where Item is the App/SampleModel
To add a validation rule, set the value of $this->validation in construct
$this->validation = [
"description" => "required|unique:business_positions"
];To specify default value, set the value of $this->defaultValue in construct. Default value only takes effect if required columns dont have value.
$this->defaultValue = [
"description" => "Default value"
];To add a foreign table, set the value of $this->requiredForeignTable in construct
$this->requiredForeignTable = [
"sample_children_table"
];By default, modifying foreign tables is not allowed. To bypass this, just set the value of $this->editableForeignTable in construct
$this->editableForeignTable = [
"sample_children_table"
];$response = array(
"data" => null,
"error" => array(),// {status, message}
"debug" => null,
"request_timestamp" => 0
);