Alex
Alex

Reputation: 8072

RESTful expand by default

How can I return model relations without adding expand parameter in url? I tried add some code in model

public function fields()
{
    $fields = parent::fields();

    $fields['profile'] = $this->profile;

    return $fields;
}

But i am getting the error:

call_user_func() expects parameter 1 to be a valid callback, no array or string given

This method works:

$_GET['expand'] = 'profile';

but it's bad solution.

Upvotes: 0

Views: 1397

Answers (1)

maswahyu
maswahyu

Reputation: 125

Try this

public function fields()
{
    $fields = parent::fields();
    $fields[] = 'profile';
    return $fields;
}

Make sure you have set the relation. Worked for me

Upvotes: 2

Related Questions