Bagisto Forum

    Bagisto

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Add profile photo option for user

    General Discussion
    2
    4
    331
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      TheBlindHawk last edited by

      hello
      I am trying to add profile photo options for the user, but I am having problems storing the photos on upload.
      My uploadImages function inside CustomerRepository:

      public function uploadImages($data)
          {
              $customer = $this->find(auth()->guard('customer')->id());
              $type = "profile_photo";
              if (isset($data[$type])) {
                  foreach ($data[$type] as $imageId => $image) {
                      $file = $type . '.' . $imageId;
                      $dir = 'customer/' . $customer->id;
      
                      if (request()->hasFile($file)) {
                          if ($customer->{$type}) {
                              Storage::delete($customer->{$type});
                          }
      
                          $customer->{$type} = request()->file($file)->store($dir);
                          $customer->save();
                      }
                  }
              } else {
                  if ($customer->{$type}) {
                      Storage::delete($customer->{$type});
                  }
      
                  $customer->{$type} = null;
                  $customer->save();
              }
          }
      

      The code skips if(request()->hasFile($file)) because it returns false.
      I call the upload function from CustomerController@upload like so:

      $this->customerRepository->uploadImages($data);
      

      The input on edit.blade.php is like so:

      <div slot="body">
                      <div class="control-group">
                          <label>プロファイルイメージ
                              <image-wrapper :button-label="'写真を入れる'" input-name="profile_photo" :multiple="false" :images='"{{ $customer->lprofile_photo}}"'></image-wrapper>
                      </div>
                  </div>
      

      I also changed other parts, but I don't think they should have any impact.
      This is a sample output I get from $data["profile_photo"]

      array (
          'image_1' => 'store_vertical.svg',
        ),
      

      Which I think is missing some stuff?
      Also I tried to add the image to validation, but it does not pass.

      $this->validate(request(), [
                  'profile_photo'         => 'image',
              ]);
      

      The code does not give any errors, and since I am still new to most things, I cannot understand what parts I'm supposed to change.

      1 Reply Last reply Reply Quote 0
      • devansh-webkul
        devansh-webkul last edited by

        This feature is already implemented in the master version.

        1 Reply Last reply Reply Quote 0
        • T
          TheBlindHawk last edited by

          Hello!
          Thank you so much for the reply!
          I didn't know the feature was added.
          Unfortunately we had to customise a lot of stuff and ended up changing a bunch of things directly in the Webkul folder, so merging the main branch directly would prove to be a problem.

          I tried copying from the following files from the master version:
          src/packages/Webkul/Customer/src/Repositories/CustomerRepository.php
          src/packages/Webkul/Customer/src/Http/Controllers/CustomerController.php
          src/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/profile/edit.blade.php

          But I think I am missing something, could you help me out?

          new empty image column:
          No errors pop up but the image is not saved and the url is not either.
          random string in the "image" column:
          error: Class 'Webkul\Customer\Repositories\Storage' not found

          Thanks again!

          1 Reply Last reply Reply Quote 0
          • T
            TheBlindHawk last edited by

            I found the pull request for it!
            It is now working, thanks again!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post