Wednesday, March 1, 2017

Laravel Registration ERROR With UNKnown Field

the script returns an error that i don't think i included in my code.

    SQLSTATE[HY000]: General error: 1364 Field 'phone' doesn't have a default 
value (SQL: insert into `users` (`name`, `email`, `location`, `password`, 
`steps`, `incubation_days`, `updated_at`, `created_at`) values (ilamini 
Ayebatonye Dagogo, dagogo@gmail.com, Uniben Road, Ugbowo, Benin City, Nigeria, 
$2y$10$aoJRS61Bn/q1eNcUFALjne8erLXD11y1.OmHhurlQJDrex73DPWJW, settings, 8, 
2017-03-01 14:11:54, 2017-03-01 14:11:54))

Can someone point me to where this phone field is coming from. Below my Register Controller Class.

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use App\paring_by_location; 
use App\Http\Controllers\Controller;
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
     */
    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, [
            'location'  => 'required|min:5',
            'name'      => 'required|max:255',
            'password'  => 'required|min:6|confirmed',
            'email'     => 'required|email|max:255',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {

    $phDay = rand(2,8);
       $user = User::create([
            'name'              => $data['name'],
            'email'             => $data['email'],
            'location'          => $data['location'],
            'password'          => bcrypt($data['password']),
            'steps'             => 'settings',
            'incubation_days'   => $phDay
        ]);

       paring_by_location::create([
            'name'      => $data['name'],
            'email'     => $data['email'],
            'location'  => $data['location'],
        ]);

      event(new \App\Events\UserReferred(request()->cookie('ref'), $user));

        return $user;
    }
}

and Below is my HomeController that i think may be Interfering with the Register Controller.

public function AccountSettings(Request $request)
    {
        $id = Auth::user()->id;

        $user = User::findOrFail($id);

        $this->validate($request, [
            'account_name'      => 'required|string|min:5',
            'account_number'    => 'required|digits:10',
            'bank_name'         => 'required|string|min:3',
            'phone'             => 'required|digits:11'
        ]);

        $input = $request->all();
        $user->update(array('steps' => 'notification'));

        $update = $user->fill($input)->save(); 





        return redirect()->route('home');

    }  

also is my USER MODEL TAHT has the protected field

 protected $fillable = [
        'name', 'email', 'password', 'location','steps','incubation_days','phone','bank_name','account_name','account_number',
    ];

So I want to understand why it is returning an error when i did not include the phone in the register controller




via dagogodboss

Advertisement