In vendor\tcg\voyager\src\Http\Controllers\VoyagerMediaController.php
...
use Illuminate\Support\Facades\Gate;
...
foreach ($storageItems as $item) {
/**
* Display of allowed folders only :
* - those that match the model permissions
* - the one who corresponds to the default role
* - those who correspond to additional roles
*/
$root_folder = explode('/', $item['path']);
$root_folder = $root_folder[0];
$dataType = Voyager::model('DataType')->where('slug', '=', $root_folder)->first();
/* If the model exists and the user has the right to navigate on this model */
$permission = $dataType && Gate::allows('browse', app($dataType->model_name));
/* If the user's default role exists and default role name is the same as the folder */
$role_principal = Auth::user()->role->name && Str::lower(Auth::user()->role->name) == $root_folder;
/* If additonal user roles exist and their name is the same as the folder name */
$roles_secondaires = Auth::user()->roles->pluck('name')->contains($root_folder);
/* So we will display the folder and its files */
if($permission || $role_principal || $roles_secondaires) {
if ($item['type'] == 'dir') {
...
With the previous example, we should only see actualites and volaille
Laravel version
9.x
PHP version
8.4.1
Voyager version
1.5
Description of problem
Show only authorized folders for a user The https://github.com/the-control-group/voyager/issues/1792 is different
Proposed solution
The use case
In the filesystem
i have these folders
The BREAD slug
The roles for the user
Folder to show in Media manager
In vendor\tcg\voyager\src\Http\Controllers\VoyagerMediaController.php
With the previous example, we should only see actualites and volaille
Alternatives considered
No response
Additional context
No response