Repository navigation
|
I am trying to create a select dropdown for a Taxonomy Model, So I can assign taxonomies and related tags to specified Models I am not sure how to have the system find all models minus Taxonomy, display the name, and store the full path to the model in the database. IE the dropdown will display USER but store Modules\Users\Models\User in the database I am trying to build this in Filament select form if that makes a difference |
Answered by
dcblogdev
Nov 19, 2024
Replies: 4 comments
|
Here's a way to dynamically get all models from all enabled modules $modules = Module::allEnabled();
$models = [];
foreach ($modules as $module) {
$modelsPath = Module::getModulePath($module->getName()) . config('modules.paths.generator.model.path');
$modulesDirectoryName = basename(config('modules.paths.modules'));
if (File::exists($modelsPath)) {
// Scan for all PHP files in the Models directory
$files = File::glob("{$modelsPath}/*.php");
foreach ($files as $file) {
$relativePath = substr($file, strpos($file, $modulesDirectoryName));
$filename = basename($file); // Extract the filename
$models[$relativePath] = $filename;
}
}
} |
0 replies
|
If you are happy to hard code you can do instead: $modelsPath = Module::getModulePath($module->getName()).'/app/Models';
$modulesDirectoryName = 'Modules'; |
0 replies
|
Slightly better version $modules = Module::allEnabled();
$models = [];
$modulesDirectoryName = basename(config('modules.paths.modules')); // Compute once
foreach ($modules as $module) {
$modelsPath = Module::getModulePath($module->getName()) . config('modules.paths.generator.model.path');
if (!File::exists($modelsPath)) {
continue; // Skip if the directory doesn't exist
}
// Scan for all PHP files in the Models directory
$files = File::glob("{$modelsPath}/*.php");
foreach ($files as $file) {
$relativePath = substr($file, strpos($file, $modulesDirectoryName));
$filename = basename($file); // Extract the filename
// Add model with relative path as key and filename as value
$models[$relativePath] = $filename;
}
} |
0 replies
Answer selected by
dcblogdev
|
Closing as answered. Thanks everyone! If you still need help on the current release, please open a new discussion. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Slightly better version