skip to Main Content

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

2

Answers


  1. 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,
            ]);
        }
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search