Question

I set up modular system in Laravel 4.1. But I have a problem with a model of a module. Here is my system scheme.

 app/modules
 app/modules/product/
 app/modules/controllers/ProductController.php
 app/modules/controllers/CatalogController.php
 app/modules/models/CatalogProductImage.php
 app/modules/models/ProductCatalog.php
 app/modules/models/CatalogProductImage.php

The problem is that, My ProductCatalog model can't see my CatalogProductImage model and hence it gives me the following error:

 Symfony \ Component \ Debug \ Exception \ FatalErrorException
 Class 'CatalogProductImage' not found

I don't know the reason. Here comes the code:

ProductCatalog.php

 <?php namespace App\Modules\Product\Models;

 use Illuminate\Auth\UserInterface;
 use Illuminate\Auth\Reminders\RemindableInterface;
 use Eloquent;
 use App\Modules\Product\Models\CatalogProductImage as CatalogProductImage;

class ProductCatalog extends Eloquent {
     protected $table           = 'catalog';
     protected $primaryKey  = 'catalogId';
     protected $connection  = 'mysql2';
     public  $timestamps        =  FALSE; //update time stamp varsa true yap, updated_at ve created_at alanlarını otomatik gunceller

     public function category() {
         return $this->hasOne('CatalogCategory', 'catalogCategoryId', 'catalogCategoryId');
     }

     public function images() {
        return $this->hasMany('CatalogProductImage', 'catalogId');
    }
 }

CatalogProductImage.php

 <?php namespace App\Modules\Product\Models;

 use Illuminate\Auth\UserInterface;
 use Illuminate\Auth\Reminders\RemindableInterface;
 use Eloquent;

 class CatalogProductImage extends Eloquent {

     protected $table            = 'catalog_image';
         protected $primaryKey  = 'catalogImageId';
     protected $connection   = 'mysql2';
         public $timestamps      =  FALSE; //update time stamp varsa true yap, updated_at ve created_at alanlarını otomatik gunceller

     public function catalog() {
         return $this->hasMany('ProductCatalog', 'catalogId');
     }

 }

Edit: I changed the CatalogProductImage From Modules... to App\Modules... but still doesn't work.

Was it helpful?

Solution 2

Ok I found the problem. I was supposed to define full path in hasMany function. Like:

    return $this->hasMany('App/Modules/Product/Models/CatalogProductImage', 'catalogId');

Not like this:

    return $this->hasMany('CatalogProductImage', 'catalogId');

OTHER TIPS

Did you add the directory in composer.json

"autoload": {
    "classmap": [
        "app/modules",
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php"
    ]
},

Then composer dump-autoload

You can also try to set it in, app/start/global.php

ClassLoader::addDirectories(array(
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top