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

Nova Creator Field Package #46

Open
dillingham opened this Issue Sep 18, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@dillingham
Collaborator

dillingham commented Sep 18, 2018

Package that sets the current authenticated user to be the BelongsTo relationship

Creator::make('Owner')->visible();

// ^ Auth user's name in disabled select box setting owner_id

Creator::make('User');

// ^ Hidden, auth user id for user_id

Probably just extend BelongsTo and override the resolve() method

Maybe Owner::make(‘Team’); ?

Isn’t too difficult to set up mutators for this but it’s also more explicit and makes models a little more dry maybe? Idk

@alexbowers

This comment has been minimized.

alexbowers commented Sep 19, 2018

This could probably be done as part of the BelongsTo with a macro.

This would work as BelongsTo::make('User')->defaultTo(..) and BelongsTo::make('User')->defaultToMe() or something.

This should be pretty easy to do

@dillingham

This comment has been minimized.

Collaborator

dillingham commented Sep 25, 2018

@alexbowers yeah. I was picturing it making a behind the scenes model event

// Order resource
Creator::make('User')
// behind the scenes
Order::saving user_id = auth()->user()->id

// Blog resource
Creator::make('Author')
// behind the scenes
Blog::saving author_id = auth()->user()->id

Creator::make('Author')
// behind the scenes
Blog::saving author_id = auth()->user()->id

Creator::make('Team')->id(auth()->user()->team->id)
// behind the scenes
Blog::saving team_id = $id
@MarceauKa

This comment has been minimized.

MarceauKa commented Oct 1, 2018

This is my solution.

For example, my Post model belongs to an User model via user_id:

public function getUserIdAttribute()
{
    return ! $this->exists && \Auth::check() ? \Auth::user()->id : null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment