Hi Everybody
I have a polymorphic relationship that an address can belong to a user or an organization. I keep getting the error 'Call to undefined method App\HTTP\Resources\User::singularLabel()'. I tried to use a static method but that didn't seem to help. The code for the files is below.
Thanks
Address.php Model
public function addressable()
{
return $this->morphTo('addressable');
}
public function getHashidsConnection()
{
return 'address';
}
User.php (Model)
public function organisation()
{
return $this->belongsTo('App\Organisation');
}
public function addresses()
{
return $this->morphMany('App\Address', 'addressable');
}
}
Address.php (Resource)
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Text::make('line_1'),
Text::make('line_2'),
Text::make('line_3'),
Text::make('post_code'),
Boolean::make('is_primary'),
MorphTo::make('Addressable')->types([
User::class,
Organisation::class,
])
];
}
public static function singularLabel()
{
return User::class;
}
User.php (Resource)
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Gravatar::make(),
Text::make('Name')
->sortable()
->rules('required', 'max:255'),
Text::make('Email')
->sortable()
->rules('required', 'email', 'max:254')
->creationRules('unique:users,email')
->updateRules('unique:users,email,{{resourceId}}'),
Password::make('Password')
->onlyOnForms()
->creationRules('required', 'string', 'min:8')
->updateRules('nullable', 'string', 'min:8'),
MorphMany::make('Addresses')
];
}