-
Notifications
You must be signed in to change notification settings - Fork 46
Closed
Description
When i call the endpoint /mail-addresses or /mail-addresses/<ID>?include=mail-domain no relationship attribute with 'mail-domain' is shown. But when i call /mail-addresses/<ID>/mail-domain i get the expected mail-domain resource! So what am i doing wrong?
In case you are wondering, /mail-domains does show the relationship attribute 'mail-addresses'.
I suspect someting is going on with pluralize or dash, but i cound't find the issue.
JSON API route
$server->resource('mail-addresses', '\\' . MailAddressController::class)
->relationships(function ($relations): void {
$relations->hasOne('mail-domain')->readOnly();
});MailAddressSchema
class MailAddressSchema extends Schema
{
/**
* The model the schema corresponds to.
*
* @var string
*/
public static string $model = MailAddress::class;
/**
* Get the resource fields.
*
* @return array
*/
public function fields(): array
{
return [
ID::make()->uuid(),
//...
BelongsTo::make('mail-domain', 'mailDomain')
->type('mail-domains')
->readonly(),
];
}MailAddress Model
class MailAddress extends BaseModel
{
use SoftDeletes;
//...
/**
* Get mail domain it belongs to.
*/
public function mailDomain(): BelongsTo
{
return $this->belongsTo(MailDomain::class, 'mail_domain_id');
}MailAddressPolicy
class MailAddressPolicy extends BasePolicy
{
public function viewMailDomain(User $user, Model $model): bool
{
return $this->view($user, $model);
}
}Metadata
Metadata
Assignees
Labels
No labels