lundi 12 novembre 2018

User registration and inserting DB with Laravel

I setup registration form. connected with request and controller. But I couldn't save the data to DB's users table. it's connected to DB, because there is one user data in the DB and when I use that's email for a new registration, it's not accepting it. But when I try to create new user no data save into DB table.

requestController

public function authorize()
    {
        return true;
    }

public function rules()
    {
        return [
            'name' => 'required|min:3|max:20',
            'email' => 'required|email|unique:users,email',
            'password' => 'required|min:6|max:20|confirmed',
            'password_conformation' => 'required|min:6|max:20'
        ];
    }

Controller

public function register(registerRequest $request)
    {
        $request->flash();

        $request['password'] = bcrypt($request->password);

        $user = new User;
        $user->fill($request->all());
        $user->save();

        return view('auth.register')->withErrors($request);
    }

and my User Model

/**
     * 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',
    ];

if you need to see form as well, i can update that code here too.. Thank you for help!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire