Unknown field error when field exists in Laravel

““class”: “ForestAdmin\LaravelForestAdmin\Exceptions\ForestException”,
“message”: “:deciduous_tree::deciduous_tree::deciduous_tree: Unknown field tiers.name for this collection”,
“code”: 0,
“file”: “[…]vendor/forestadmin/laravel-forestadmin/src/Services/Concerns/HasFilters.php:376”,”

Feature(s) impacted

Using filters and viewing collection on ‘tiers’

Observed behavior

When querying, or viewing the ‘tiers’ table, throws an error. The database does have a tiers.name and is used by our API and platform via Laravel.

Expected behavior

Shows data or uses field in query

Failure Logs

““class”: “ForestAdmin\LaravelForestAdmin\Exceptions\ForestException”,
“message”: “:deciduous_tree::deciduous_tree::deciduous_tree: Unknown field tiers.name for this collection”,
“code”: 0,
“file”: “[…]vendor/forestadmin/laravel-forestadmin/src/Services/Concerns/HasFilters.php:376”,”

Context

  • Project name: …
  • Team name: …
  • Environment name: … Development & Production
  • Agent type & version: … 1.2.1
  • Recent changes made on your end if any: … N/A

Hi @EFGP,

I think your schema is not up to date.
In your development environment I don’t see the collection in your .forestadmin-schema.json file.

Could you updated it :pray:
FYI there is a little trick to updated it, just run the following command:
php artisan forest:send-apimap

more information here : https://docs.forestadmin.com/documentation/how-tos/settings/laravel-specific-settings#send-apimap-on-deploy

1 Like

The model still isn’t part of the schema. This seems to have changed in the last couple of updates since 1.2.0, we used to be able to at least navigate via the “Tier” relationship, if not query against it. Now as of 1.2.2 the relationships are blank in forestadmin.

I’ve had a look on our end and the Tier model as you say isn’t in the schema locally either in the json. This may be because of a couple of things:

  1. The Tier class isn’t in the root Model folder, it’s in App/Tiers/Tier.php rather than App/Models/Tier/Tier/php alongside the other models.

  2. The underlying table is “Tiers” but the class is called “Tier”. The model has protected $table = “tiers” on the model though.

We can potentially solve this on our end by manually updating the schema - but imagine this will just get overwritten everytime we serve the app, and won’t work on production.

I will DM you the Tier class we are using.

Hello @EFGP,

I have just looked at the schema history on the development environment.
Previously until 2022-11-01 19:36:13 the schema had the model Tier (with namespace App/Models).
But since 2022-11-01 20:04:31 the model is no longer present in the schema.

I have a very simple solution to fix this problem :slight_smile:
Just edit the config/forest.php file and change the 1st line like this:

‘models_directory’ => [‘app/Models’, ‘app/Tiers’],

Tell me if it works :slight_smile:

2 Likes

That seems to have resolved it, although it’s not showing in the collections list (which doesn’t really matter for us, it’s more of just a reference table). Thanks for the help.

1 Like

Glad that it works :raised_hands:

The collection is hidden by default. You have to click on the “edit layout” button and then in the collection list click on the eye icon.

Example:
Screenshot 2022-11-25 at 16.58.30

Ahah sorry still getting used to the UI - thanks!

1 Like