laravel-friendships icon indicating copy to clipboard operation
laravel-friendships copied to clipboard

Groups in config

Open nikolaynesov opened this issue 9 years ago • 9 comments

Right now we define groups in config this way:

'groups' => [
        'acquaintances' => 0,
        'close_friends' => 1,
        'family' => 2
    ]

It means that developer has to associate a name to each group somewhere else based on slug. for ex:

[
...
'close_friends' => 'Close Friends',
...
]

What do you think if we let developer specify public names right in the config. I see 2 ways of doing this.

  1. Use only slugs like 'best_friend' and not indexes to store a group in DB. It will take more space in DB, but makes it more readable. Then config should look like
'groups' => [
        'acquaintances' => 'Acquaintances',
        'close_friends' => 'Close Friends',
        'family' => 'My Family'
    ]
  1. Use array for each group.
'groups' => [
0 => [
'slug'=> 'acquaintances',
'name'=> 'Acquaintances'
],
1 => [
'slug'=> 'close_friends',
'name'=> 'Close Friends'
],
2 => [
'slug'=> 'family',
'name'=> 'My Super Family'
]
]

What do you think would be a better way?

nikolaynesov avatar Oct 07 '16 12:10 nikolaynesov

Hm, I think that first way looks better since it more dynamic. Meaning that if a dev decides to remove some groups the config will remain clean instead of having something like this:

'groups' => [
0 => [
'slug'=> 'acquaintances',
'name'=> 'Acquaintances'
],
4 => [
'slug'=> 'close_friends',
'name'=> 'Close Friends'
],
5 => [
'slug'=> 'family',
'name'=> 'My Super Family'
]
]

However, what do you think about storing the groups in the db?

hootlex avatar Oct 08 '16 01:10 hootlex

@hootlex I was also thinking about that but it's another migration and table for usually 1-3 rows (close friends, family, acquaintances). We can do that though.

nikolaynesov avatar Oct 08 '16 06:10 nikolaynesov

With introducing a table we can allow each user have his own set of groups... but it's another story. What do you think?

nikolaynesov avatar Oct 08 '16 06:10 nikolaynesov

Hmm. I haven't thought about this yet. I was just asking 😄

We can discuss the db solution when we are migrating to V2.

hootlex avatar Oct 08 '16 08:10 hootlex

@nikolaynesov (I've sent you an invitation for the Gitter room)

hootlex avatar Oct 08 '16 08:10 hootlex

I'd be willing to pitch in, I used the package in one of my projects, would like to help make it better :)

JadJabbour avatar Nov 11 '16 08:11 JadJabbour

@JadJabbour I am happy to hear that. Do you have something specific in mind?

hootlex avatar Nov 11 '16 22:11 hootlex

@hootlex moving groups into database sounds really cool, as in most cases groups are not predefined but managed by the users themselves, and moreover, each has own set of groups for his/her "friends".

cspshadx avatar Feb 06 '17 16:02 cspshadx

i have some problem in join a friend in a group $user = Auth::user(); $group_name=user_group::find($group_id); $friend=Friendship::find($friend_id); $user->groupFriend($friend, $group_name);

I have not any idea for the parameter in groupFriend($friend, $group_name);

its give error Argument 1 passed to Illuminate\Database\Grammar::columnize() must be of the type array, string given, called in /var/www/html/krug_me/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php on line 131 and defined

harpreetsinghdhiman500 avatar Apr 11 '17 12:04 harpreetsinghdhiman500