I want to store image path in database. My Controller code undervendorlaravelframeworksrcIlluminateFoundationAuthRegistersUsers.php
follows:
public function register(Request $request)
{
$this->validator($request->all())->validate();
if($request->hasFile('image')) {
$image_name = $request->file('image')->getClientOriginalName();
$image_path = $request->file('image')->store('public');
$user->image = Storage::url($image_name);
$user->save();
}
event(new Registered($user = $this->create($request->all())));
// $this->guard()->login($user); disable autologin for new users
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
I am getting the following error: ErrorException in RegistersUsers.php line 40: Creating default object from empty value .
The image is getting saved in public folder but not able to save image path in the user table database. schema of user table
Schema::create('users', function (Blueprint $table) {
$table->increments('user_id');
$table->string('name');
$table->string('image');
$table->rememberToken();
$table->timestamps();
how to proceed to store the image path in the user table in database
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…