Too few Arguments to Function

Asked

Viewed 1,289 times

0

I created a route to register users in Aravel:

Route::post('registrar', 'Auth\RegisterController@create');

My class:

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'nome', 'email', 'telefone', 'senha', 'usuario_anjo'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

My controller:

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */

    /**
     * Create a new controller instance.
     *
     * @return void
     */

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'nome' => 'required|string|max:255',
            'email' => 'required|string|email|max:255|unique:users',
            'senha' => 'required|string|min:6|confirmed',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {
        return User::create([
            'nome' => $data['nome'],
            'email' => $data['email'],
            'telefone' => $data['telefone'],
            'usuario_anjo' => $data['usuario_anjo'],
            'senha' => Hash::make($data['senha']),
        ]);
    }
}

I’m trying through the Postman hit the route created, but returns:

"Too few Arguments to Function App Http Controllers Auth Registercontroller::create(), 0 passed and Exactly 1 expected"

I’m sending the keys:

name: x email: [email protected] password: xxx User name: 1 telephone: 999999

  • Receive a Request as a parameter instead of the array. In this case Laravel is basically saying that it is waiting for a parameter, which is the array and vc is not sending anything. NO create method exchange $data array for Request $request.

  • worked out, thanks

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.