Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller getForm runs before middleware #2710

Open
kfina-planxy opened this issue Dec 12, 2024 · 0 comments
Open

Controller getForm runs before middleware #2710

kfina-planxy opened this issue Dec 12, 2024 · 0 comments

Comments

@kfina-planxy
Copy link

kfina-planxy commented Dec 12, 2024

Description

The ModuleController method getForm() runs before any middleware is run.

Why is that a problem?

It makes it impossible to modify the form based on user.

// example 1: Not every field available to every user
if (Auth::user()->hasPermissionTo('admin'))
  $form-add(Input::make()->name('admin_only_field'));
// example 2: Select options based on user
$form->add(Select::make()->name('posts')->options(Options::make([ Auth::user()->posts->map(fn($p) => Option::make([$p->id, $p->title])) ])));

Both of these do not work, because Auth::user() is not available (yet).

Steps to reproduce

add dd(Auth::id()) to the getForm method

Expected result

I get a dd with the value 1 (id of the current user)

Actual result

I get a dd with the value null

Versions

Twill version: 3.3.1
Laravel version: 11.0
PHP version: 8.2
Database engine: MySQL (Xampp)

Note

I would also be content with some kind of hack to achieve this behavior, but I couldn't figure out which vendor files to overwrite for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant