Undefined property on ForestAdmin ID

Feature(s) impacted

Rending ‘details’ view of a model, e.g. clicking into a record

Observed behavior

Shows " Your server encountered an error " forest screen - behind the scenes has
Undefined property ForestAdmin\LaravelForestAdmin\Auth\Guard\Model\ForestUser::$id

Expected behavior

Shows detail view of record

Failure Logs

ForestAdmin\LaravelForestAdmin\Auth\Guard\Model\ForestUser::$id undefined property

We have Laravel Policies in place which could be effecting this - but the list views work. Assume it’s an issue with the ‘store’ method but we’re in read-only forest mode anyway.

I’m able to supply our Policy/Model/Controller files in DMs with any ForestAdmin staff for further assistance.

Context

  • Project name: …
  • Team name: …
  • Environment name: 1.2.1
  • Agent type & version:
  • Recent changes made on your end if any: Setting up on development

Hi @EFGP,

Thanks for your valuable feedback.
I hope this is not blocking for you, right now.

The agent team will go back to you early next week to dig into this.

Thanks for your patience.

Absolutely fine! Enjoy your weekends.

Hello @EFGP

I can’t reproduce the issue on my end.
Have you override the forest “show” route ?
Does the problem occur on every model ?

As you suggest I would like you to send me the code (Policy/Model/Controller) that could solve this issue :pray:.

Hi,

No this is a fresh 1.2.1 install, we’ve not touched the underlying forest routes. This only occurs on certain models.

I will send the policy/model/controller and forest.json

Hi - the relevant files / HAR from the forestadmin and schema json have been sent by DM.

1 Like

I confirm there is a conflict with our policy. Your policy is called and ours is ignored.

As a result, your User::current() code conflicts with our guard forest.

While waiting for our fix, I can offer you a workaround.
In your policy, in the view, update and delete methods, you can add the following code:

 if (!auth()->guard()->user instanceof ForestUser) {
            $user = User::current() ;
            return ....
        }
return true ;

The namespace of ForestUser is : use ForestAdmin\LaravelForestAdmin\Auth\Guard\Model\ForestUser ;

Sorry for the inconvenience.

1 Like

I created a ticket on our board.

You’ll receive a message on this thread once we have patched it.

Excellent thank you - speedy as always!

I’ll update this on our development branch and let you know if that resolves the issue.

2 Likes

Hi @matthv

That seems to have worked, we tweaked the suggestion slightly as ‘guard()->user’ as an attribute was protected and reversed the bool logic so returns sooner (personal preference!):

  if (auth()->guard()->user() instanceof ForestUser) {
            return true;
  }
1 Like

Hi @EFGP

The fix will soon be released.
You can already test it, if you want.

You just have to edit the composer.json file with the following code:

"repositories": [
    {
        "type": "git",
        "url": "https://github.com/ForestAdmin/laravel-forestadmin.git"
    }
],
 "require": {
   ...
   "forestadmin/laravel-forestadmin": "dev-fix/forest-policy-conflict",
   ...
},

then run composer install

1 Like

Hello @EFGP

The fix has been released on the new version 1.2.2.

Best regards

1 Like