fathomminds/php-rest-models

View on GitHub
documentation/api/model/resource.md

Summary

Maintainability
Test Coverage
## Model::resource($resource = null) ##

Returns the Model's currently set resource object

### Parameters ###

*(mixed)* $resource If the parameter is provided it is set as the Model's resource

### Returns ###

*(object)* Returns a reference to an instance of an object of the SchemaClass configured

### Throws ###

*RestException*

### Example code ###

```php
<?php
namespace YourApp\Logic;

use Fathomminds\Rest\Exceptions\RestException;
use YourApp\Models\FooModel;

class Do
{
    public function something()
    {
        try {
            $model = new FooModel();
            $model->one('KEY');
            $title = $model->resource()->title;
            $resource = new \StdClass;
            $resource->title = 'TITLE';
            $title = $model->resource($resource)->title;
        } catch (RestException $exception) {
            $message = $exception->getMessage();
            $details = $exception->getDetails();
        }
    }
}

```