Error adding column in table 'users' Standard

Asked

Viewed 113 times

0

Used make:auth and changed the table 'users', but whenever I try to register a user I come across this error:

BadMethodCallException
Method Illuminate\Validation\Validator::validateMatricula does not exist.

This is the code of Registercontroller:

<?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
{


    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * 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, [
            'name' => ['required','string','max:255'],
            'email' => ['required','string','email','max:255','unique:users'],
            'matricula' => ['required','string','matricula','max:255','unique:users'],
            'password' => ['required','string','min:8','confirmed'],
        ]);
    }

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

And this is code from the 'users' table':

    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('matricula')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
  • In the validation array there is also this validation?

1 answer

0


Have you checked the Motel? The name is User.php, it’s on app/User.php:

namespace App;

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

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

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

It is important that if you are adding a new column to the $fillable the column name, example:

 protected $fillable = [
        'name', 'email', 'password', 'matricula',
    ];

I believe that’s the problem, I used this site as reference: techiescircle.com, and saw that you performed all the steps, removing the view, but missed only that.

There are some video lessons on the site of Alavel and also saw it there, it is very good to learn the basics until the advanced framework, however it is all in English and without subtitles, however can modify the speed to be able to follow. This is the first episode Laravel 5.7 From Scratch.

Browser other questions tagged

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