protected $load_relationships;
public function __construct()
{
$this->load_relationships = ['vendor','approval_status','appservice_components.component','categories'];
}
public function store(StoreVendorApplicationServiceRequest $request, $vendor_id)
{
$vendor = $this->vendor->findOrFailUuid($vendor_id);
$request_data = $request->all();
//create application service
$application_service = $vendor->appservices()->create($request_data);
//create application service components
$application_service->appservice_components()->create($request_data);
//create applicaton service categories
if ($request->filled('categories')) {
$application_service->categories()->attach($request->categories);
}
//create applications service tags
if ($request->filled('tags')) {
$application_service->attachTags($request->tags);
}
$resource = new ApplicationServiceResource($application_service->load($this->load_relationships));
return $this->responseCreated($resource);
}
<?php
namespace App\Http\Resources\V1\ApplicationService;
use Illuminate\Http\Resources\Json\Resource;
class ApplicationServiceResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}