• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Register
  • Login
Bagisto Forum

Bagisto

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

Custom package dependencies classes not found

Knowledge Base
2
5
858
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.
  • O
    Okumura last edited by 9 Sept 2024, 14:21

    Re: Custom Package dependencies

    Hi, I am creating custom package that has composer.json document in itself and uses library:

    "stichoza/google-translate-php"
    

    I installed it in package location:

    "bagistoProject/packages/myNamespace/myPackage"
    

    with command:

    composer require stichoza/google-translate-php
    

    My composer.json inside my package contains:

    "require": {
            "stichoza/google-translate-php": "dev-master"
        }
    

    and I applied command in root bagistoProject directory:

    composer dump-autoload
    

    However, if I try to include it in controller:

    ...
    use Stichoza\GoogleTranslate\GoogleTranslate;
    
    class MyCustomController extends Controller
    {
        public function index()
        {
            $translator = new GoogleTranslate();
            return view('mypackage::view-location');
        }
    }
    

    I get error:

    Class "Stichoza\GoogleTranslate\GoogleTranslate" not found
    

    I can find vendor directory and all classes generated by composer in:

    "bagistoProject/packages/myNamespace/myPackage/vendor/stichoza/google-translate-php/src"
    

    I tried to implement the same package in laravel project and it works without problems. What am I missing?

    1 Reply Last reply Reply Quote 0
    • Rishabh-Webkul
      Rishabh-Webkul last edited by 10 Sept 2024, 06:18

      Hello @Okumura

      Firstly check that your custom package is running or not.

      Then check you have followed all the necessary steps regarding the installation of the package installation

      https://github.com/bagisto/bagisto-package-generator

      Thanks & Regards

      O 1 Reply Last reply 11 Sept 2024, 14:41 Reply Quote 0
      • O
        Okumura @Rishabh-Webkul last edited by 11 Sept 2024, 14:41

        @Rishabh-Webkul
        My custom package is running fine. I did all the steps for creating the package but it doesn't come with composer.json document. I found bagisto article that shows how to correctly set up it by hand:
        https://bagisto.com/en/how-to-create-a-package-in-bagisto-v2-0/
        but it still doesn't include required libraries in my packages.

        My current solution is in document:

        bagistoProject/packages/MyNamespace/MyPackage/src/Providers/MyPackageServiceProvider.php
        

        and in register method include:

        class MyPackageServiceProvider extends ServiceProvider
        {
            public function register()
            {
                $packageVendorPath = __DIR__ . '/../../vendor/autoload.php';
                if (file_exists($packageVendorPath)) {
                    require_once $packageVendorPath;
                }
                ...
            }
        }
        

        If there is better solution please inform me. I want it to be as simple as possible for customers to set up.

        Thanks and best regards.

        1 Reply Last reply Reply Quote 0
        • Rishabh-Webkul
          Rishabh-Webkul last edited by 12 Sept 2024, 12:59

          Hello @Okumura

          Kindly make sure you have installed all the required dependencies inside the root vendor.

          Thanks & Regards

          O 1 Reply Last reply 12 Sept 2024, 22:34 Reply Quote 0
          • O
            Okumura @Rishabh-Webkul last edited by 12 Sept 2024, 22:34

            Hi @Rishabh-Webkul
            Dependencies doesn't exist in root vendor but as I understand based on article: "https://forums.bagisto.com/topic/3288/custom-package-dependencies" it shouldn't be.

            As I understand packages should have separate dependencies and be completely independent. If I install package at root level for example:

            composer require stichoza/google-translate-php
            

            customer will need to do the same thing. If I use few libraries it could be a long list of instructions how to set up my package and it wouldn't be modular solution. My current solution seems to be the simplest option for now.

            Thanks and best regards.

            1 Reply Last reply Reply Quote 0
            1 out of 5
            • First post
              1/5
              Last post