Skip to content

Commit b00b3f5

Browse files
committed
Update a more flexible way to customize folders accessibility (#19)
1 parent dbabfdb commit b00b3f5

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/config/lfm.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828
// If true, share folder will be created when allow_multi_user is true.
2929
'allow_share_folder' => true,
3030

31-
// The database column to identify a user. Make sure the value is unique.
32-
// Ex: When set to 'id', the private folder of user will be named as the user id.
33-
'user_field' => 'id',
31+
// Flexibla way to customize client folders accessibility
32+
// Ex: The private folder of user will be named as the user id.
33+
'user_field' => function() {
34+
return empty(auth()->user()) ? '' : auth()->user()->id;
35+
},
3436

3537
/*
3638
|--------------------------------------------------------------------------

src/traits/LfmHelpers.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,14 @@ public function sortFilesAndDirectories($arr_items, $sort_type)
378378

379379
public function getUserSlug()
380380
{
381-
$slug_of_user = config('lfm.user_field');
381+
if (is_callable(config('lfm.user_field'))) {
382+
$slug_of_user = call_user_func(config('lfm.user_field'));
383+
} else {
384+
$old_slug_of_user = config('lfm.user_field');
385+
$slug_of_user = empty(auth()->user()) ? '' : auth()->user()->$old_slug_of_user;
386+
}
382387

383-
return empty(auth()->user()) ? '' : auth()->user()->$slug_of_user;
388+
return $slug_of_user;
384389
}
385390

386391
public function error($error_type, $variables = [])

0 commit comments

Comments
 (0)