wadigchan
@wadigchan

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

Argument 1 passed to App\Http\Controllers\Auth\RegisterController::create() must be an instance of Illuminate\Http\Request

Q&A

Closed

解決したいこと

Tinder風アプリ作成をやっているのですが、エラーが出てしまいます。

発生している問題・エラー

TypeError
Argument 1 passed to App\Http\Controllers\Auth\RegisterController::create() must be an instance of Illuminate\Http\Request, array given, called in C:\xampp\tinder-webapp\vendor\laravel\ui\auth-backend\RegistersUsers.php on line 34

該当するソースコード

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;
use Illuminate\Auth\Events\Registered;

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 = RouteServiceProvider::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'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }

    public function regiater(Request $request)
    {
        $this->validator( $request->all() )->validate();

        event(new Registered($user=$this->create($request) ));

        $this->guard()->login($user);

        if($response=$this->registered($request,$user))
        {
            return $response;
        }

        return $request->wantsJson()
            ? new JsonResponse([],201)
            : redirect( $this->redirectPath() );
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  Request $request
     * @return \App\Models\User
     */
    protected function create(Request $request)
    {
        dd($request->all());

        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }
}

自分で試したこと

この箇所に原因があるようですがいまいちよくわかっていません。
詳しい方、回答のほどよろしくお願いします。

protected function create(Request $request)
    {
        dd($request->all());

        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }
0

1Answer

called in C:\xampp\tinder-webapp\vendor\laravel\ui\auth-backend\RegistersUsers.php on line 34

こちらから呼び出された時にエラーになっています。
create()の引数はIlluminate\Http\Requestを必要としていますが、配列が与えられているようです。

0Like

Comments

  1. @wadigchan

    Questioner

    こんばんは。
    いつも本当にありがとうございます。
    RegistersUsers.phpをもう一度念入りに書き直してみたところ成功しました。
    凡ミスすみません、、ありがとうございます!!

Your answer might help someone💌