Skip to content

Instantly share code, notes, and snippets.

@necrogami
Created October 8, 2015 15:18
Show Gist options
  • Select an option

  • Save necrogami/b99e1d7b9b1620ceb4d4 to your computer and use it in GitHub Desktop.

Select an option

Save necrogami/b99e1d7b9b1620ceb4d4 to your computer and use it in GitHub Desktop.
<?php
namespace Titan\Model;
use Titan\Model\TitanModel;
use Illuminate\Database\Eloquent\Model;
use Titan\Model\JsonTransformer\Company as Transformer;
use Titan\Model\Address;
class Company extends Model
{
use TitanModel;
public $timestamps = false;
protected $table = 'company';
public function qbCustomer()
{
return $this->hasOne(\App\Modules\QuickBooks\Model\Customer::class, 'qb_id', 'qb_id');
}
}
<?php
namespace Titan\Model\JsonTransformer;
use Titan\Model\Company as Model;
use League\Fractal\TransformerAbstract;
use League\Fractal\ParamBag;
class Company extends TransformerAbstract
{
/**
* List of resources possible to include
*
* @var array
*/
protected $availableIncludes = [
'address',
'brand',
'category',
'collateral',
'contact',
'email',
'event',
'location',
'notification',
'note',
'phone',
'status',
'summary',
'url',
'viewedLine',
'personCompany',
'storeTypes',
'storeType',
'emailType',
'phoneType',
'qbCustomer',
];
/**
* @param \Illuminate\Database\Eloquent\Model $company
* @return array
*/
public function transform(Model $company)
{
return [
'id' => (int) $company->id,
'name' => $company->name,
'status' => $company->status,
'options' => $company->options,
'other' => $company->other,
'qb_id' => $company->qb_id,
'_links' => [
[
'rel' => 'self',
'uri' => '/api/v1/data/company/'.$company->id,
]
],
];
}
/**
*
* @param Model $model
* @param \League\Fractal\ParamBag $params
* @return \League\Fractal\Resource\Collection
*/
public function includeQbCustomer(Model $model, ParamBag $params = null)
{
return $this->item($model->qbCustomer, new \App\Modules\QuickBooks\Transformer\Customer, 'qbCustomer');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment