0

To update a user I used a FormRequest named UserByAdminFormRequest like this :

public function rules()
    {
        switch ($this->method()) {
            case 'GET':
            case 'DELETE': {
                //some Rules
            }
            case 'POST': {
                //some Rules
            }
            case 'PUT':
                $user_id = $this->get('user_id');

                dd($this);

                return [
                    'name'        => 'required',
                    'email'       => 'email|unique:users,email,' . $user_id . ',user_id',
                    'password'    => 'min:4',
                    're-password' => 'required_unless:password,' . NULL . '|same:password',
                ];


            case 'PATCH': {
                //some Rules
            }
            default:
                break;
        }

As you can see email field should be unique but to ignore current user in this case, I need to her user_id value.

For that I used $this->get('user_id') but it return null value always.

I used that FormRequest like this in my controller :

public function update(UserByAdminFormRequest $request, \App\User $user)
    {
        //
    }

And the url that I called by PUT method is (for example) :

http://api.zarsystem.dev/v1/dashboard/user/7

What can I do in this case Or is there any alternate ways?

1 Answer 1

1

instead of

$this->get('user_id')

you need to use

$this->user_id

to get the value of user id, make sure you have input field or hidden filed with name user_id.

Sign up to request clarification or add additional context in comments.

1 Comment

I found that I should be used $this->user->user_id and problem is solved now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.