angular post function give me a problem when i want to signup

Artin Zareie Source

I want to make a jwt api with laravel and angular , but i have a problem ; when i send my signup data to my laravel server it say's :

Argument 1 passed to Illuminate\Database\Eloquent\Builder::create() must be of the type array, object given, called in D:\xampp\htdocs\MySiteBackEnd\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php on line 23

and my data is :

{
      email : "[email protected]"
      family  : "aa"
      name  : "aa"
      password  : "aaa"
      password_confirmation : "aaa"
      username : "a"
}   

my backend signup function is :

public function signup(SignUpRequest $request)
    {
        User::create($request);
        return $this->login($request);
    }

my login code is :

public function login()
    {
        $credentials = request(['email', 'password']);

        if (! $token = auth()->attempt($credentials)) {
            return response()->json(['error' => 'ایمیل یا رمزعبور نامعتبر می باشد .'], 401);
        }

        return $this->respondWithToken($token);
    }

and finaly , my SignUpRequest class is this :

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class SignUpRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required',
            'family' => 'required',
            'email' => 'required|email|unique:users',
            'username' => 'required|unique:users',
            'password' => 'required|confirmed',
        ];
    }
}

i'm using angular 6 and laravel 5.7

phpangularlaraveljwt

Answers

answered 4 weeks ago Pourbahrami #1

On your signup method just use User::create($request->all()); instead of User::create($request);

comments powered by Disqus