Recent Topics

Storing Data through Repository Error



  • Hello,

    I have created a new package with name Blogs and Provider is Ebest. Below is my code:-

    packages/Ebest/Blogs/src/Models/BlogCategory.php

    use Illuminate\Database\Eloquent\Model;
    use Webkul\Core\Eloquent\TranslatableModel;
    use Kalnoy\Nestedset\NodeTrait;
    use Illuminate\Support\Facades\Storage;
    use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
    use Ebest\Blogs\Contracts\BlogCategory as BlogCategoryContract;
    use Ebest\Blogs\Repositories\BlogsCategoryRepository;
    
    class BlogCategory extends Model implements BlogCategoryContract
    {
        use NodeTrait;
    
        public $translatedAttributes = [
            'name',
            'description',
            'slug',
            'url_path',
            'meta_title',
            'meta_description',
            'meta_keywords',
        ];
    
        protected $fillable = [
            'position',
            'status',
        ];
    
        protected $with = ['translations'];
    
        public function image_url()
        {
            if (! $this->image)
                return;
    
            return Storage::url($this->image);
        }
    
        public function getImageUrlAttribute()
        {
            return $this->image_url();
        }
    }
    
    

    packages/Ebest/Blogs/src/Models/BlogCategoryProxy.php

    <?php
    
    namespace Ebest\Blogs\Models;
    
    use Konekt\Concord\Proxies\ModelProxy;
    
    class BlogCategoryProxy extends ModelProxy
    {
    
    }
    

    packages/Ebest/Blogs/src/Contracts/BlogCategory.php

    <?php
    
    namespace Ebest\Blogs\Contracts;
    
    interface BlogCategory
    {
        
    }
    

    packages/Ebest/Blogs/src/Repositories/BlogCategoryRepository.php

    <?php
    
    namespace Ebest\Blogs\Repositories;
    
    use Illuminate\Container\Container as App;
    use Illuminate\Support\Facades\Storage;
    use Illuminate\Support\Facades\Event;
    use Webkul\Core\Eloquent\Repository;
    use Ebest\BLogs\Models\BlogCategory;
    use Illuminate\Database\Eloquent\ModelNotFoundException;
    use Illuminate\Support\Facades\DB;
    
    class BlogsCategoryRepository extends Repository
    {
        /**
         * Specify Model class name
         *
         * @return mixed
         */
        function model()
        {
            return 'Ebest\Blogs\Contracts\BlogCategory';
        }
    
        public function create(array $data)
        {
            // Event::dispatch('catalog.category.create.before');
    
            if (isset($data['locale']) && $data['locale'] == 'all') {
                $model = app()->make($this->model());
    
                foreach (core()->getAllLocales() as $locale) {
                    foreach ($model->translatedAttributes as $attribute) {
                        if (isset($data[$attribute])) {
                            $data[$locale->code][$attribute] = $data[$attribute];
                            $data[$locale->code]['locale_id'] = $locale->id;
                        }
                    }
                }
            }
    print_r($data); exit();
            $category = $this->model->create($data);
    
            $this->uploadImages($data, $category);
    
            if (isset($data['attributes'])) {
                $category->filterableAttributes()->sync($data['attributes']);
            }
    
            // Event::dispatch('catalog.category.create.after', $category);
    
            return $category;
        }
    }
    

    packages/Ebest/Blogs/src/Providers/ModuleServiceProvider.php

    <?php
    
    namespace Ebest\Blogs\Providers;
    
    use Konekt\Concord\BaseModuleServiceProvider;
    
    class ModuleServiceProvider extends BaseModuleServiceProvider
    {
        protected $models = [
            Ebest\Blogs\Models\BlogCategory::class,
        ];
    }
    

    config/concord.php

    <?php
    
    return [
        'modules' => [
            /**
             * Example:
             * VendorA\ModuleX\Providers\ModuleServiceProvider::class,
             * VendorB\ModuleY\Providers\ModuleServiceProvider::class
             *
             */
    
            \Webkul\Attribute\Providers\ModuleServiceProvider::class,
            \Webkul\BookingProduct\Providers\ModuleServiceProvider::class,
            \Webkul\Category\Providers\ModuleServiceProvider::class,
            \Webkul\Checkout\Providers\ModuleServiceProvider::class,
            \Webkul\Core\Providers\ModuleServiceProvider::class,
            \Webkul\Customer\Providers\ModuleServiceProvider::class,
            \Webkul\Inventory\Providers\ModuleServiceProvider::class,
            \Webkul\Product\Providers\ModuleServiceProvider::class,
            \Webkul\Sales\Providers\ModuleServiceProvider::class,
            \Webkul\Tax\Providers\ModuleServiceProvider::class,
            \Webkul\User\Providers\ModuleServiceProvider::class,
            \Webkul\CatalogRule\Providers\ModuleServiceProvider::class,
            \Webkul\CartRule\Providers\ModuleServiceProvider::class,
            \Webkul\CMS\Providers\ModuleServiceProvider::class,
            \Webkul\Velocity\Providers\ModuleServiceProvider::class,
            \Webkul\SocialLogin\Providers\ModuleServiceProvider::class,
            \Ebest\Blogs\Providers\ModuleServiceProvider::class,
        ]
    ];
    

    Whenever i am running the project it gives error as: "

    Class Ebest\Blogs\Providers\Ebest\Blogs\Models\BlogCategory must extend or implement Ebest\Blogs\Providers\Ebest\Blogs\Contracts\BlogCategory.
    
      at D:\xampp\htdocs\bagisto\vendor\konekt\concord\src\Concord.php:126
        122|      */
        123|     public function registerModel(string $abstract, string $concrete, $registerRouteModel = true)
        124|     {
        125|         if (!is_subclass_of($concrete, $abstract, true)) {
      > 126|             throw new InvalidArgumentException("Class {$concrete} must extend or implement {$abstract}. ");
        127|         }
        128| 
        129|         $this->models[$abstract] = $concrete;
        130|         $this->app->alias($concrete, $abstract);
    
      1   D:\xampp\htdocs\bagisto\vendor\konekt\concord\src\BaseServiceProvider.php:262
          Konekt\Concord\Concord::registerModel("Ebest\Blogs\Providers\Ebest\Blogs\Contracts\BlogCategory", "Ebest\Blogs\Providers\Ebest\Blogs\Models\BlogCategory")
    
      2   D:\xampp\htdocs\bagisto\vendor\konekt\concord\src\BaseServiceProvider.php:98
          Konekt\Concord\BaseServiceProvider::registerModels()
    
    D:\xampp\htdocs\bagisto>ss Ebest\Blogs\Providers\Ebest\Blogs\Models\BlogCategory must extend or
    

    Please Help.
    Thanking You



  • Hi @himanshu-kmr,

    Just run php artisan config:cache.



  • I tried several time by optimizing and also clearing the cache. But still problem is there...



  • Hi @himanshu-kmr,

    Look at this namespace Ebest\Blogs\Providers\Ebest\Blogs\Models\BlogCategory. Something is wrong with this namespace. It should be like this Ebest\Blogs\Models\BlogCategory.

    Please check the namespace. A namespace is not correct.



  • @devansh-webkul said in Storing Data through Repository Error:

    BlogCategory

    In the BlogCategory model the name space is namespace Ebest\Blogs\Models;



  • Hi @himanshu-kmr,

    If you are sure that namespace is correct then do one thing. Go to bootstrap/cache folder and delete all files inside that.

    After that run composer dump-autoload and then php artisan optimize.

    If still facing any issue then check each file and namespace because it is a namespace issue check that errors it's clearly specifying the wrong namespace.



  • @devansh-webkul Thankyou. The problem was in ModuleServiceProvider

    I changed

    protected $models = [
            Ebest\Blogs\Models\BlogCategory::class,
        ];
    

    to
    protected $models = [
    \Ebest\Blogs\Models\BlogCategory::class,
    ];

    This problem has been resolved.

    Now if i am running the project i am getting error as

    Class 'Ebest\Blogs\Models\BlogCategoryProxy ' not found

    at D:\xampp\htdocs\bagisto\vendor\konekt\concord\src\Concord.php:269


Log in to reply