I'm following the instruct of https://docs.flarum.org/extend/models#frontend-models.
Errors
app.store.find('/st/invitation')
const invitations = app.store.all('invitations');
console.log(invitations.invited_user_id())
And then I got errors:
mount-redraw.js:15 TypeError: invitations.invited_user_id is not a function
at ProfilePage.stevetribeItems (ProfilePage.js:36:31)
at ProfilePage.content (ProfilePage.js:21:35)
at n.view (UserPage.js:56:73)
at Function.a (render.js:30:16)
at render.js:155:45
at render.js:160:3
at c (render.js:66:8)
at l (render.js:50:5)
at render.js:103:4
at c (render.js:62:15)
but this single statement works as expected.
app.store.find('/st/invitation').then(console.log)
Model.js
import Model from 'flarum/common/Model';
export default class invitations extends Model {
invitor_user_id = Model.attribute('invitor_user_id');
invited_user_id = Model.attribute('invited_user_id');
remarks = Model.attribute('remarks');
created_at = Model.attribute('created_at', Model.transformDate);
}
index.js
app.initializers.add('tpam-stevetribe', function(app) {
app.routes['st.invite.view'] = { path: '/st', component: ProfilePage };
app.store.models.invitations = invitations
addProfilePage();
});
Laravel Serializer
<?php
namespace TPam\SteveTribe\Serializer;
use Flarum\Api\Serializer\AbstractSerializer;
use TPam\SteveTribe\Model\Invitations;
class InvitedUserSerializer extends AbstractSerializer
{
/**
* {@inheritdoc}
*/
protected $type = 'invitations';
/**
* {@inheritdoc}
*/
protected function getDefaultAttributes($Invitations){
return [
'invitor_user_id' => $Invitations->invitor_user_id,
'invited_user_id' => $Invitations->invited_user_id,
'remarks' => $Invitations->remarks,
'created_at' => $Invitations->created_at
];
}
}