Search code examples
laravellaravel-9laravel-api

upload avatar with some key value data in Postman for laravel web application


any body can help me i wanna make a register which is have these parameter

this is my RegisterRequest for validation

 public function rules()
    {
        return [
            'name'     => 'required',
            'email'    => 'required|email|unique:users,email',
            'username' => 'nullable|string|min:5|unique:users,username',
            'avatar'   => 'nullable|mimes:jpge,jpg,png',
            'password' => 'required|string|min:5',
            
        ];
    }

and this is my Postman Setup Headers setup enter image description here

Body / form-data setup enter image description here

Body /raw enter image description here


and this is my register method dd() code

 public function register(RegisterRequest $request)
    {

        dd(
            $request->all(),
            $request->avatar,
            $request->hasFile('avatar'),
            $request->file('avatar')
        );


    }

and this is the result in the Postman

enter image description here


Solution

  • Its solved By removing this from Headers

    Content-Type : application/json