Cannot fetch data from models which are not in App/Models namespace

Feature(s) impacted

For laravel models from namespace other than App\Models, data is not accessilble

Observed behavior

  • Model is visible in list of collections
  • When trying to fetch data, there is error message “The request to your server either failed or returned invalid data.
    Please check your console logs to get more information.”
  • AJAX request which should return the data yields only “Server Error”

Expected behavior

  • Model data is disponible even for models from non-default namespace

Context

Project name: Hector Mentoring - preprod
Team name: Operations
Environment name: Developement
Agent type & version: v1.0.0-beta.21 + Laravel Framework 9.3.1
Recent changes made on your end if any: API was updated with php artisan forest:send-apimap

Hi @tslominski, and welcome to our community :wave:

Currently we have a feature that could help you.

This feature fixes the namespace issue and offers the ability to have several directories for models (different of App\Models).

You can try this feature by adding this line into your composer.json

"repositories": [
    {
        "type": "git",
        "url": "https://github.com/ForestAdmin/laravel-forestadmin.git"
    }
],
 "require": {
   ...
   "forestadmin/laravel-forestadmin": "dev-feat/multi-directories-models",
   ...
},

The config/forest.php has been slightly changed.

You can remove the 'models_namespace' key and replace 'models_directory' => env('MODEL_DIRECTORY', 'app/Models/') by 'models_directory' => ['app/Models'].

1 Like

Hi @tslominski,

This feature is now available in the latest version (v1.1.1) of laravel-forestadmin.