Try changing this
protected function create(array $data)
to
public function create(Request $data)
To store the image you can use intervention
Hi, I'm trying to upload an image in laravel default user registration. I'm using laravel ui package.
Here is create method in RegisterController
protected function create(array $data) {
if (request()->hasFile('image')) {
$image = request()->file('image')->getClientOriginalName();
request()->file('image')->storeAs('avatars', $image, 'public');
}
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'address' => $data['address'],
'image' => $image ,
'contact' => $data['contact'],
'password' => Hash::make($data['password']),
]);
I'm getting this error TypeError
Argument 1 passed to App\Http\Controllers\Auth\RegisterController::create() must be an instance of Illuminate\Http\Request, array given
What is the right way to upload an image when registering?
@ihprince also ensure you have
enctype="multipart/form-data"
in your form or you wont be able to pass images when you post.
Please or to participate in this conversation.