0
votes

I am trying to make register and log in in laravel 5.2, but am receiving

Type error: Argument 1 passed to Illuminate\Database\Eloquent\Model::create() must be of the type array, null given, called in /Applications/XAMPP/xamppfiles/htdocs/blogs/app/Http/Controllers/RegisterationController.php on line 30

Here is my registerationcontroller:

   <?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

    use App\Http\Requests;
    use App\User;

    class RegisterationController extends Controller
    {
        //

        public function create(){
            return view('sessions.create');
        }

        public function store(){

            //validate form

            $this->validate(request(),[
                'name' => 'required',
                'email' => 'required|email',
                'password' => 'required'
                ]);


            //store the data
            $user = User::create(request(['name','email','password']));

            //login
             auth()->login($user);

             //redirect

             return redirect()->home();
        }
    }

and here is the user model:

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * 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',
    ];

    public function posts(){
        return $this->hasMany(Post::class);
    }

}

i am following video for laravel 5.4, not sure if this is the problem.

1

1 Answers

1
votes

You are not passing an array to the function you are passing the result of a function called request() which probably does not exist.

So amend the call something like this

//$user = User::create(request(['name','email','password']));
$user = User::create(
                    [ 
                        $request->input('name'),
                        $request->input('email'),
                        $request->input('password')
                    ]
                    );

or

$params = [ $request->input('name'),
            $request->input('email'),
            $request->input('password')
          ];
$user = User::create( $params );

or

User::create($request->only(['name','email','password']);