i am trying to upload an image as a profile picture in laravel bootstrap auth package. in this i am trying to change some package files to upload image. also i added a column in users table.
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'campus_id' => $data['campus_id'],
'role' => $data['role'],
'remarks' => $data['remarks'],
'image' => $data['image'],
]);
}
i make changes in Auth controller in validation function also makes some changes in user store function
CodePudding user response:
I think you need to move user profile image before create its entry inside database.
protected function create(array $data)
{
$imageName = time().'.'.$data['image']->extension();
//$data['image']->move(public_path('images'), $imageName);
$data['image']->storeAs('public/images', $imageName);
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'campus_id' => $data['campus_id'],
'role' => $data['role'],
'remarks' => $data['remarks'],
'image' => $imageName,
]);
}
CodePudding user response:
You can use Image intervention for this. After installing you can use it in your controller as use Image;
$image = $request->file('image');
$img_name = hexdec(uniqid()).'.'.$image->getClientOriginalExtension();
Image::make($image)->resize( 847.5, 431 )->save('uploads/sliders/'.$img_name);
$image_path = 'uploads/sliders/'.$img_name;
Slider::create([
'title' => $request->title,
'image' => $image_path,
'created_at' => Carbon::now()
]);
1st you need to move your image to your desired directory inside public folder and save that directory in the database.