Cee_Bee's avatar

User related Models

Apologies if this has been asked before and if its a common question. I tried searching about it but struggled to find the right search terms.

I am waiting to get say all the categories for a authorised user. (Auth::user()->categories;) I created a method in the User Model for a belongs to many that returns all the categories for that user and works! But this seems wrong to me as I would expected to get it via the Category Model rather than through the user model. Is the way I have done it correct?

Thanks!

0 likes
2 replies
Unsociable's avatar
Level 1

@callumbee Yep that's fine, so if you want to load the categories for a user you would do user()->categories, You can also expand categories with eloquent search methods like user()->where('created_at' > now()->subDay());

1 like

Please or to participate in this conversation.